Websphere 7 MQueue:如何从 Java 访问队列深度?

发布于 2024-12-09 20:34:24 字数 648 浏览 0 评论 0原文

我想编写一些代码来监视 Websphere 7 MQ 上的队列大小。 这是我想出的代码

   MQEnvironment.hostname = "10.21.1.19"; 
   MQEnvironment.port = 1414;
   MQEnvironment.channel = "SYSTEM.CDEF.SVRCONN";
   MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);

   MQQueueManager qMgr = new MQQueueManager("MYQMGR");

   MQQueue destQueue = qMgr.accessQueue("PUBLISH", MQC.MQOO_INQUIRE);
   System.out.println(destQueue.getCurrentDepth());
   destQueue.close();
   qMgr.disconnect();

我如何知道“频道”是什么?

我如何知道传递给 MQQueueManager 的队列管理器名称是什么?

或者我应该看看另一个 API 吗?

我需要它与 WRS 7 SIB 和 MQ 一起使用。

谢谢 杰夫·波特

I'd like to write some code to monitor the queue size on Websphere 7 MQ.
This is the code I've come up with

   MQEnvironment.hostname = "10.21.1.19"; 
   MQEnvironment.port = 1414;
   MQEnvironment.channel = "SYSTEM.CDEF.SVRCONN";
   MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);

   MQQueueManager qMgr = new MQQueueManager("MYQMGR");

   MQQueue destQueue = qMgr.accessQueue("PUBLISH", MQC.MQOO_INQUIRE);
   System.out.println(destQueue.getCurrentDepth());
   destQueue.close();
   qMgr.disconnect();

How do I know what the "Channel" is?

How do I know what the queue manager name is that I pass into MQQueueManager?

Or is there another API that I should look at?

I need it work with WRS 7 SIB and MQ.

Thanks
Jeff Porter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

层林尽染 2024-12-16 20:34:24

中的 jar

我使用 WS 7.0.1.1 com.ibm.mq.jar
com.ibm.mq.jmqi.jar
com.ibm.mq.jmqi.system.jar
com.ibm.mq.commonservices.jar
com.ibm.mq.headers..jar
com.ibm.mq.jmqi.remote.jar

我从“IBM Webshpere MQ Explorer”(树中的客户端连接节点)获得了队列管理器名称和通道名称

    import com.ibm.mq.MQEnvironment;
    import com.ibm.mq.MQQueue;
    import com.ibm.mq.MQQueueManager;
    import com.ibm.mq.constants.CMQC;
    int openOptions = CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_INPUT_SHARED;

    MQEnvironment.hostname = "10.2.51.19";
    MQEnvironment.port = 1414;
    MQEnvironment.channel = "SW1_QM_CH1";

    MQQueueManager qMgr = new MQQueueManager("SW1_QM");

    MQQueue destQueue = qMgr.accessQueue("E_RETRY",   openOptions);
    System.out.println("E_RETRY size:" + destQueue.getCurrentDepth());
    destQueue.close();
    qMgr.disconnect();

希望这对其他人有帮助!

I used the jars from WS 7.0.1.1

com.ibm.mq.jar
com.ibm.mq.jmqi.jar
com.ibm.mq.jmqi.system.jar
com.ibm.mq.commonservices.jar
com.ibm.mq.headers..jar
com.ibm.mq.jmqi.remote.jar

I got the Queue Manager name and the Channel name from "IBM Webshpere MQ Explorer" (Client Connection node in the tree)

    import com.ibm.mq.MQEnvironment;
    import com.ibm.mq.MQQueue;
    import com.ibm.mq.MQQueueManager;
    import com.ibm.mq.constants.CMQC;
    int openOptions = CMQC.MQOO_INQUIRE + CMQC.MQOO_FAIL_IF_QUIESCING + CMQC.MQOO_INPUT_SHARED;

    MQEnvironment.hostname = "10.2.51.19";
    MQEnvironment.port = 1414;
    MQEnvironment.channel = "SW1_QM_CH1";

    MQQueueManager qMgr = new MQQueueManager("SW1_QM");

    MQQueue destQueue = qMgr.accessQueue("E_RETRY",   openOptions);
    System.out.println("E_RETRY size:" + destQueue.getCurrentDepth());
    destQueue.close();
    qMgr.disconnect();

Hope this helps someone else out!

你是暖光i 2024-12-16 20:34:24

如果您想要同时适用于 SIBus 和 MQ 实现的东西,您最好坚持使用 JMS API(因为这些 API 也可以移植到 JMS 的其他实现)。

所以我要做的是:

//ctx is InitialContext
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/CF");
Connection conn = cf.createConnection();
conn.start();

Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("jms/MyQueue");
QueueBrowser qb = session.createBrowser(queue);

//sadly, getting this enum is the best the JMS API can offer.
//but the upside is the code is portable AND it can run over MQ and SIBus
//implementations.
Enumeration queueMessageEnum = qb.getEnumeration();
int count = 0;
while(queueMessageEnum.hasMoreElements()) {
  queueMessageEnum.nextElement();
  count++;
}

If you want something that works for both SIBus and MQ implementations you are best to stick with the JMS API's (as these are then also portable to other implementations of JMS as well).

So what I'd do is:

//ctx is InitialContext
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/CF");
Connection conn = cf.createConnection();
conn.start();

Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup("jms/MyQueue");
QueueBrowser qb = session.createBrowser(queue);

//sadly, getting this enum is the best the JMS API can offer.
//but the upside is the code is portable AND it can run over MQ and SIBus
//implementations.
Enumeration queueMessageEnum = qb.getEnumeration();
int count = 0;
while(queueMessageEnum.hasMoreElements()) {
  queueMessageEnum.nextElement();
  count++;
}
叫思念不要吵 2024-12-16 20:34:24

这是另一种方法;我使用 WS 7.0.1.1 中的 jars。

import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.CMQCFC;
import com.ibm.mq.pcf.MQCFH;
import com.ibm.mq.pcf.PCFAgent;
import com.ibm.mq.pcf.PCFParameter;


PCFAgent agentNode = new PCFAgent(HOST_NAME, PORT, CHANNEL_NAME);

MQCFH cfh = new MQCFH(agentNode.send(CMQCFC.MQCMD_INQUIRE_Q, {new MQCFST(CMQC.MQCA_Q_NAME, QUEUE_NAME)})[0]);

PCFParameter p;

if (cfh.reason == 0) {
  for (int i = 0; i < cfh.parameterCount; i++) {
     p = PCFParameter.nextParameter(responses[0]);
     int parm = p.getParameter();
     switch (parm) {
         case CMQC.MQIA_CURRENT_Q_DEPTH:
              currentDepth = (Integer) p.getValue();
              break;
         case CMQC.MQIA_MAX_Q_DEPTH:
              maximumDepth = (Integer) p.getValue();
              break;
     }
  }
}

Here is another way; I used the jars from WS 7.0.1.1.

import com.ibm.mq.constants.CMQC;
import com.ibm.mq.constants.CMQCFC;
import com.ibm.mq.pcf.MQCFH;
import com.ibm.mq.pcf.PCFAgent;
import com.ibm.mq.pcf.PCFParameter;


PCFAgent agentNode = new PCFAgent(HOST_NAME, PORT, CHANNEL_NAME);

MQCFH cfh = new MQCFH(agentNode.send(CMQCFC.MQCMD_INQUIRE_Q, {new MQCFST(CMQC.MQCA_Q_NAME, QUEUE_NAME)})[0]);

PCFParameter p;

if (cfh.reason == 0) {
  for (int i = 0; i < cfh.parameterCount; i++) {
     p = PCFParameter.nextParameter(responses[0]);
     int parm = p.getParameter();
     switch (parm) {
         case CMQC.MQIA_CURRENT_Q_DEPTH:
              currentDepth = (Integer) p.getValue();
              break;
         case CMQC.MQIA_MAX_Q_DEPTH:
              maximumDepth = (Integer) p.getValue();
              break;
     }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文