Getting MQ Queue Statistics in Java

From my application, I need to request Web-Sphere MQ per-queue statistics (the last time the message was received / posted, the number of messages en / dequeued, the current queue queue, the number of connected clients). I managed to get the queue depth through PCFAgent, but I got a little stuck on the rest because the IBM documentation is rather confusing.

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

+4
source share
1 answer

If you installed the WMQ client in the default location, the samples will look like this: C:\Program Files (x86)\IBM\WebSphere MQ\tools\pcf\samples .

In UNIX flavors, they end with /opt/mqm/samp .

If you just grabbed the jar files and did not install the client, then you will not have a supported configuration - or samples, tracing utilities, diagnostic tools, etc. etc. Client installation media is available for free download on the SupportPacs page. Various clients are currently available:

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

UPDATE:

Here are some code snippets for performing the requested functions:

First you need the connection of the queue manager ( qmgr ). Then you can create 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 (with the exception of the enq / deq pointer) below. Note that in order to receive the latest msg get \ put message, you need to enable queue monitoring ( MONQ ).

 // 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 get perfumes using:

 pcfResp = pcfAgent.send(inquireQueueStatus); 

For each individual package, you can use the getXXXXXParameterValue method ( XXXXXX is the data type).

To count Enq / Deq 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.

+9
source

Source: https://habr.com/ru/post/1393810/


All Articles