Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't get MQ Reset Stats to work properly

Status
Not open for further replies.

klamerus

Programmer
Jun 23, 2003
71
0
0
US
I've written the following program in MS VC on Windows XP and I'm testing it with a queue (Test1) on my system.

Although it doesn't failure or throw errors, it doesn't appear to be resetting stats. At least, I can't tell if it is or not, but it's not returning the # of enqueues and dequeues properly (or I'm not reading them properly).

Can anyone figure out what's wrong with this and provide advice or a fix. I'd like to get this working so I can check on "traffic flow" through a queue I need to monitor.



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include <cmqc.h>
#include <cmqcfc.h>
#include <cmqbc.h>


void CheckCallResult( MQCHAR *, MQLONG , MQLONG );


int
main(
int argc,
char * argv[ ] )
{
MQHCONN hConn;
MQCHAR qmName[ MQ_Q_MGR_NAME_LENGTH + 1 ] = "";
MQLONG compCode, reason;
MQHBAG adminBag = MQHB_UNUSABLE_HBAG;
MQHBAG responseBag = MQHB_UNUSABLE_HBAG;
MQHBAG qAttrsBag;
MQLONG mqEnqCount, mqDeqCount;
MQLONG numberOfBags, i;


printf( "Display enqueues and dequeues of local queues\n\n" );


if ( argc > 1 )
strncpy( qmName, argv[ 1 ], ( size_t ) MQ_Q_MGR_NAME_LENGTH );


MQCONN( qmName, &hConn, &compCode, &reason );
CheckCallResult( "MQCONN()", compCode, reason );

if ( compCode == MQCC_FAILED )
exit( ( int ) reason );


mqCreateBag( MQCBO_ADMIN_BAG, &adminBag, &compCode, &reason );
CheckCallResult( "mqCreateBag(adminBag)", compCode, reason );

mqCreateBag( MQCBO_ADMIN_BAG, &responseBag, &compCode, &reason );
CheckCallResult( "mqCreateBag(responseBag)", compCode, reason );


mqAddString( adminBag, MQCA_Q_NAME, MQBL_NULL_TERMINATED, "Test1", &compCode, &reason );
CheckCallResult( "mqAddString(Test1)", compCode, reason );


mqExecute( hConn, MQCMD_RESET_Q_STATS, MQHB_NONE, adminBag, responseBag, MQHO_NONE, MQHO_NONE, &compCode, &reason );
CheckCallResult( "mqExecute(MQCMD_RESET_Q_STATS)", compCode, reason );

if ( compCode != MQCC_OK )
exit( ( int ) reason );


mqCountItems( responseBag, MQHA_BAG_HANDLE, &numberOfBags, &compCode, &reason );
CheckCallResult( "mqCountItems(numberOfBags)", compCode, reason );

printf( "There are %d bags in the result collection\n", numberOfBags );

for ( i = 0; i < numberOfBags; i++ )
{
mqInquireBag( responseBag, MQHA_BAG_HANDLE, i, &qAttrsBag, &compCode, &reason );
CheckCallResult( "mqInquireBag(responseBag)", compCode, reason );

mqInquireInteger( qAttrsBag, MQSEL_ANY_SELECTOR, 3, &mqEnqCount, &compCode, &reason );
CheckCallResult( "mqInquireInteger(mqEnqCount)", compCode, reason );

printf( "There are %d enqueues on Test1\n", mqEnqCount );

mqInquireInteger( qAttrsBag, MQSEL_ANY_SELECTOR, 2, &mqDeqCount, &compCode, &reason );
CheckCallResult( "mqInquireInteger(mqDeqCount)", compCode, reason );

printf( "There are %d dequeues on Test1\n", mqDeqCount );
}


if ( adminBag != MQHB_UNUSABLE_HBAG )
{
mqDeleteBag( &adminBag, &compCode, &reason );
CheckCallResult( "mqDeleteBag(adminBag)", compCode, reason );
}

if ( responseBag != MQHB_UNUSABLE_HBAG )
{
mqDeleteBag( &responseBag, &compCode, &reason );
CheckCallResult( "mqDeleteBag(responseBag)", compCode, reason );
}


MQDISC( &hConn, &compCode, &reason );
CheckCallResult( "MQDISC()", compCode, reason );


return( 0 );
}


void
CheckCallResult(
char *callText,
MQLONG cc,
MQLONG rc )
{
if ( cc != MQCC_OK )
printf( "%-50s failed: Completion Code = %d : Reason = %d\n", callText, cc, rc );
else
printf( "%-50s succeeded: Completion Code = %d : Reason %d\n", callText, cc, rc );
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top