Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting MQ queue statistics in Java

From my application I need to query some Websphere MQ per-queue statistics (last message get/put time, number of en/dequeued messages, current queue depth, number of connected clients). I managed to get the queue depth via PCFAgent, but I'm kind of stuck on the rest because the IBM documentation is rather confusing.

Do you know any useful references (or code examples) that might help?

like image 404
CAFxX Avatar asked Jan 18 '23 15:01

CAFxX


1 Answers

If you installed the WMQ client in the default location then the samples will be at: C:\Program Files (x86)\IBM\WebSphere MQ\tools\pcf\samples.

On UNIX flavors, they end up under /opt/mqm/samp.

If you just grabbed the jar files and did not install the client then you won't have a supported configuration - or the samples, tracing utilities, diagnostic tools, etc., etc. The client install media is available for free download in the SupportPacs page. The different clients currently available are:

  • Version 6.0 is SupportPac MQC6 (V6 is end of life Sept 2012)
  • Version 7.0 is SupportPac MQC7
  • Version 7.1 is SupportPac MQC71

Make sure that you are looking at the Infocenter for the version of WebSphere MQ Server that you are connecting to. Also note that if you connect to a v7 QMgr and are using a v6 client, then the constants and classes you are using will limit you to the v6 functionality. Preferably, use the latest client since it is always backward compatible with older QMgr versions.

UPDATE:

Here are some code snippets to perform the requested functions:

First you need a queue manager connection (qmgr). Then you can create a PCFMessageAgent:

// Create PCF Message Agent
try {
    pcfAgent = new PCFMessageAgent(qmgr);
} catch (MQException mqe) {
    System.err.println("PCF Message Agent creation ended with reason code "
                       + mqe.reasonCode);
    return mqe.reasonCode;
}

You can get most of the attributes you need using (except the enq/deq count) the call below. Note that in order to get last msg get\put time you need to turn queue monitoring (MONQ) on.

// Prepare PCF command to inquire queue status (status type)
inquireQueueStatus = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q_STATUS);
inquireQueueStatus.addParameter(CMQC.MQCA_Q_NAME, "name of queue to inquire");
inquireQueueStatus.addParameter(CMQCFC.MQIACF_Q_STATUS_TYPE, CMQCFC.MQIACF_Q_STATUS);
inquireQueueStatus.addParameter(CMQCFC.MQIACF_Q_STATUS_ATTRS, new int[] {
                  CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH,
                  CMQCFC.MQCACF_LAST_GET_DATE, CMQCFC.MQCACF_LAST_GET_TIME,
                  CMQCFC.MQCACF_LAST_PUT_DATE, CMQCFC.MQCACF_LAST_PUT_TIME,
                  CMQCFC.MQIACF_OLDEST_MSG_AGE, CMQC.MQIA_OPEN_INPUT_COUNT,
                  CMQC.MQIA_OPEN_OUTPUT_COUNT, CMQCFC.MQIACF_UNCOMMITTED_MSGS });

You can retrieve the parms using:

pcfResp = pcfAgent.send(inquireQueueStatus);

The for each individual parms you can use the getXXXXXParameterValue method (XXXXXX is the type of data).

For the Enq/Deq counts, you need to reset the queue statistics:

// Prepare PCF command to reset queue statistics
queueResetStats = new PCFMessage(CMQCFC.MQCMD_RESET_Q_STATS);
queueResetStats.addParameter(CMQC.MQCA_Q_NAME, queueName);

pcfResp3 = pcfAgent.send(queueResetStats);

queueMsgDeqCount = pcfResp3[0].getIntParameterValue(CMQC.MQIA_MSG_DEQ_COUNT);
queueMsgEnqCount = pcfResp3[0].getIntParameterValue(CMQC.MQIA_MSG_ENQ_COUNT);

Let me know if you have more questions.

like image 113
T.Rob Avatar answered Jan 26 '23 06:01

T.Rob