Getting MQ queue statistics in Java

14,444

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:

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.

Share:
14,444
CAFxX
Author by

CAFxX

Yak-shaving for a living

Updated on June 04, 2022

Comments

  • CAFxX
    CAFxX almost 2 years

    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?

  • CAFxX
    CAFxX over 12 years
    The ListQueueDepth sample is what I already used to get the queue depth. Unfortunately it appears there are no samples covering the other statistics I need (last message get/put time, number of en/dequeued messages, number of connected clients).
  • CAFxX
    CAFxX over 12 years
    Thanks for the exhaustive reply! Too bad the enq/deq counts require resetting the stats, that's a showstopper.
  • T.Rob
    T.Rob over 12 years
    I refer to that as the "WMQ's quantum API call": the act of observing the value changes the value. I never really liked the behavior either. If you want to request a new function "inquire queue statistics", please use the WMQ Request form at bit.ly/WMQReq