/*****************************************************************************/ /* */ /* (c) Copyright IBM Corp. 2003 All rights reserved. */ /* */ /* This sample program is owned by International Business Machines */ /* Corporation or one of its subsidiaries ("IBM") and is copyrighted */ /* and licensed, not sold. */ /* */ /* You may copy, modify, and distribute this sample program in any */ /* form without payment to IBM, for any purpose including developing, */ /* using, marketing or distributing programs that include or are */ /* derivative works of the sample program. */ /* */ /* The sample program is provided to you on an "AS IS" basis, without */ /* warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, */ /* EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Some jurisdictions do not allow for the exclusion or limitation of */ /* implied warranties, so the above limitations or exclusions may not */ /* apply to you. IBM shall not be liable for any damages you suffer as */ /* a result of using, modifying or distributing the sample program or */ /* its derivatives. */ /* */ /*****************************************************************************/ /* */ /* Program name: qstatus */ /* */ /* Description: This sample demonstates how to retrieve information about */ /* processes that have a queue open. */ /* */ /* Function: This sample uses the MQAI interface to send a */ /* MQCMD_INQUIRE_Q_STATUS with a status type of */ /* MQIACF_Q_HANDLE to the command server. */ /* It retrieves the reply from the command server in a */ /* temporary dynamic queue and parses out the queue status */ /* attributes and presents them to standard out. */ /* This sample is based on amqsailq.c */ /* */ /* Prereqs: This sample program requires WebSphere MQ 5.3 */ /* */ /* */ /* Build: This program has been tested with WebSphere MQ 5.3.0.1 */ /* on Windows/2000 using Visual C++ 6.0 compiler. */ /* Build using the command: */ /* */ /* cl qstatus.c mqm.lib */ /* */ /* Execute: Run this program with the command: */ /* qstatus queuename */ /* where queuename is the name of a local queue or a */ /* a name containing wildcard characters. */ /* */ /*****************************************************************************/ /******************************************************************************/ /* Includes */ /******************************************************************************/ #include #include #include #include #include /* MQI */ #include /* PCF */ #include /* MQAI */ #define WAIT_TIME 5000 /* wait time for mqexecute */ /******************************************************************************/ /* Function prototypes */ /******************************************************************************/ void CheckCallResult(MQCHAR *, MQLONG , MQLONG); /******************************************************************************/ /* Function: main */ /******************************************************************************/ int main(int argc, char *argv[]) { /***************************************************************************/ /* MQAI variables */ /***************************************************************************/ MQHCONN hConn; /* handle to MQ connection */ MQCHAR qmName[MQ_Q_MGR_NAME_LENGTH+1]=""; /* default QMgr name */ MQCHAR qName[MQ_Q_NAME_LENGTH+1]=""; /* queue name to query */ MQLONG reason; /* reason code */ MQLONG connReason; /* MQCONN reason code */ MQLONG compCode; /* completion code */ MQHBAG adminBag = MQHB_UNUSABLE_HBAG; /* admin bag for mqExecute */ MQHBAG responseBag = MQHB_UNUSABLE_HBAG; /* response bag for mqExecute */ MQHBAG optionsBag = MQHB_UNUSABLE_HBAG; /* options bag for mqExecute */ MQHBAG qAttrsBag; /* bag containing q attributes */ MQHBAG errorBag; /* bag containing cmd server error */ MQLONG mqExecuteCC; /* mqExecute completion code */ MQLONG mqExecuteRC; /* mqExecute reason code */ MQLONG strAttrLength; /* Actual length of q name */ MQLONG intAttr; /* integer attribute returned */ MQLONG i; /* loop counter */ MQLONG numberOfBags; /* number of bags in response bag */ MQCHAR strAttr[256]; /* string attribute returned */ if (argc < 2) { printf("Syntax: %s queuename \n",argv[0]); printf("\tqueuename may contain wildcard characters.\n"); exit(-1); } strncpy(qName, argv[1], MQ_Q_NAME_LENGTH); printf("\nDisplay current status of queue %s\n\n", qName); /***************************************************************************/ /* Connect to the queue manager */ /***************************************************************************/ if (argc > 2) strncpy(qmName, argv[2], (size_t)MQ_Q_MGR_NAME_LENGTH); MQCONN(qmName, &hConn, &compCode, &connReason); /***************************************************************************/ /* Report the reason and stop if the connection failed. */ /***************************************************************************/ if (compCode == MQCC_FAILED) { CheckCallResult("Queue Manager connection", compCode, connReason); exit( (int)connReason); } /***************************************************************************/ /* Create an admin bag for the mqExecute call */ /***************************************************************************/ mqCreateBag(MQCBO_ADMIN_BAG, &adminBag, &compCode, &reason); CheckCallResult("Create admin bag", compCode, reason); /***************************************************************************/ /* Create a response bag for the mqExecute call */ /***************************************************************************/ if (compCode == MQCC_OK) { mqCreateBag(MQCBO_ADMIN_BAG, &responseBag, &compCode, &reason); CheckCallResult("Create response bag", compCode, reason); } /***************************************************************************/ /* Create an options bag to set the timeout value of the mqexecute call */ /***************************************************************************/ if (compCode == MQCC_OK) { mqCreateBag(MQCBO_USER_BAG, &optionsBag, &compCode, &reason); CheckCallResult("Create options bag", compCode, reason); if (compCode == MQCC_OK && reason == MQRC_NONE) { mqAddInteger(optionsBag, MQIACF_WAIT_INTERVAL, WAIT_TIME, &compCode, &reason); } /********************************************************/ /* If generating the options bag fails, just use the */ /* default time of 30 seconds by setting options bag */ /* to MQHB_NONE */ /********************************************************/ if (compCode != MQCC_OK) { optionsBag = MQHB_NONE; compCode = MQCC_OK; reason = MQRC_NONE; } } /***************************************************************************/ /* Put the queue name into the admin bag */ /***************************************************************************/ if (compCode == MQCC_OK) { mqAddString(adminBag, MQCA_Q_NAME, MQBL_NULL_TERMINATED, qName, &compCode, &reason); CheckCallResult("Add q name", compCode, reason); } /***************************************************************************/ /* Put the status type into the admin bag */ /* Type must be HANDLE to get open status detail */ /***************************************************************************/ if (compCode == MQCC_OK) { mqAddInteger(adminBag, MQIACF_Q_STATUS_TYPE, MQIACF_Q_HANDLE, &compCode, &reason); CheckCallResult("Add status type", compCode, reason); } /***************************************************************************/ /* Indicate we want all attributes */ /***************************************************************************/ if (compCode == MQCC_OK) { mqAddInteger(adminBag, MQIACF_Q_STATUS_ATTRS, MQIACF_ALL, &compCode, &reason); CheckCallResult("Add status attrs", compCode, reason); } /***************************************************************************/ /* The mqExecute call creates the PCF structure required, sends it to */ /* the command server, and receives the reply from the command server into */ /* the response bag. The attributes are contained in system bags that are */ /* embedded in the response bag, one set of attributes per bag. */ /***************************************************************************/ if (compCode == MQCC_OK) { mqExecute(hConn, /* MQ connection handle */ MQCMD_INQUIRE_Q_STATUS,/* Command to be executed */ optionsBag, /* No options bag */ adminBag, /* Handle to bag containing commands */ responseBag, /* Handle to bag to receive the response*/ MQHO_NONE, /* Put msg on SYSTEM.ADMIN.COMMAND.QUEUE*/ MQHO_NONE, /* Create a dynamic q for the response */ &compCode, /* Completion code from the mqexecute */ &reason); /* Reason code from mqexecute call */ } /***************************************************************************/ /* Check the command server is started. If not exit. */ /***************************************************************************/ if (reason == MQRC_CMD_SERVER_NOT_AVAILABLE) { printf("Please start the command server: \n"); MQDISC(&hConn, &compCode, &reason); CheckCallResult("Disconnect from Queue Manager", compCode, reason); exit(98); } /***************************************************************************/ /* Check the result from mqExecute call. If successful find the current */ /* depths of all the local queues. If failed find the error. */ /***************************************************************************/ if ( compCode == MQCC_OK ) /* Successful mqExecute */ { /*************************************************************************/ /* Count the number of system bags embedded in the response bag from the */ /* mqExecute call. The attributes for each queue are in a separate bag. */ /*************************************************************************/ mqCountItems(responseBag, MQHA_BAG_HANDLE, &numberOfBags, &compCode, &reason); CheckCallResult("Count number of bag handles", compCode, reason); for ( i=0; i