简体   繁体   English

在Java中获取MQ队列统计信息

[英]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). 从我的应用程序中,我需要查询一些Websphere MQ每队列统计信息(最后消息获取/放置时间,en / dequeued消息数,当前队列深度,连接客户端数)。 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. 我设法通过PCFAgent获得队列深度,但我有点坚持其余,因为IBM文档相当混乱。

Do you know any useful references (or code examples) that might help? 您是否知道可能有用的任何有用的参考(或代码示例)?

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 . 如果您将WMQ客户端安装在默认位置,那么示例将位于: C:\\Program Files (x86)\\IBM\\WebSphere MQ\\tools\\pcf\\samples

On UNIX flavors, they end up under /opt/mqm/samp . 在UNIX风格上,它们最终在/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 . 如果您只是抓住了jar文件并且没有安装客户端,那么您将没有受支持的配置 - 或样本,跟踪实用程序,诊断工具等等。客户端安装介质可以在SupportPacs中免费下载页面 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. 确保您正在查看Infocenter以获取要连接的WebSphere MQ Server版本。 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. 另请注意,如果连接到v7 QMgr并使用v6客户端,则您使用的常量和类将限制您使用v6功能。 Preferably, use the latest client since it is always backward compatible with older QMgr versions. 最好使用最新的客户端,因为它总是向后兼容较旧的QMgr版本。

UPDATE: 更新:

Here are some code snippets to perform the requested functions: 以下是一些代码片段,用于执行所请求的功能:

First you need a queue manager connection ( qmgr ). 首先,您需要一个队列管理器连接( qmgr )。 Then you can create a PCFMessageAgent : 然后你可以创建一个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. 您可以使用下面的调用获得所需的大多数属性(enq / deq计数除外)。 Note that in order to get last msg get\\put time you need to turn queue monitoring ( MONQ ) on. 请注意,为了获得最后的msg get \\ put时间,您需要打开队列监视( 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 retrieve the parms using: 您可以使用以下方法检索parms:

pcfResp = pcfAgent.send(inquireQueueStatus);

The for each individual parms you can use the getXXXXXParameterValue method ( XXXXXX is the type of data). 对于每个单独的parms,您可以使用getXXXXXParameterValue方法( XXXXXX是数据类型)。

For the Enq/Deq counts, you need to reset the queue statistics: 对于Enq / Deq计数,您需要重置队列统计信息:

// 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. 如果您有更多问题,请与我们联系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM