监控 IBM MQ 使用 Java

huangapple go评论112阅读模式
英文:

Monitoring IBM MQ with java

问题

我如何使用标准IBM MQ库从IBM MQ中使用Java发现队列深度和其他有关队列的指标?

英文:

How do I discover the Queue depth, and other metrics about queues, from IBM MQ using java with standard IBM MQ libraries?

答案1

得分: 1

尝试以下示例代码片段以获取队列深度。

String mqQMgr = "";
String mqQueue = "";

MQEnvironment.hostname = "";
MQEnvironment.port = "";
MQEnvironment.channel = "";
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);

MQQueueManager qMgr = new MQQueueManager(mqQMgr);
MQQueue destQueue = qMgr.accessQueue(mqQueue, openOptions);

int depth = destQueue.getCurrentDepth();
destQueue.close();
qMgr.disconnect();

完整的代码版本(根据需要更改参数,如绑定或客户端模式、选项等):

import com.ibm.mq.*;

public class QueueManager {

    private final String host;
    private final int port;
    private final String channel;
    private final String manager;
    private final MQQueueManager qmgr;

    public QueueManager(String host, int port, String channel, String manager) throws MQException {
        this.host = host;
        this.port = port;
        this.channel = channel;
        this.manager = manager;
        this.qmgr = createQueueManager();
    }

    private MQQueueManager createQueueManager() throws MQException {
        MQEnvironment.channel = channel;
        MQEnvironment.port = port;
        MQEnvironment.hostname = host;
        MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
        return new MQQueueManager(manager);
    }

    // 此方法将返回队列深度
    public int queueDepth(String queueName) {
       int depth = -1;
       int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING;
       MQQueue queue = null;
       try {
          queue = qmgr.accessQueue(queueName, openOptions);
          depth = queue.getCurrentDepth();
       }
       catch (MQException e)
       {
          System.out.println("CC=" +e.completionCode + " : RC=" + e.reasonCode);
       }
       finally {
          try {
             if (queue != null)
                queue.close();
          }
          catch (MQException e) {
             System.out.println("CC=" +e.completionCode + " : RC=" + e.reasonCode);
          }
       }

       return depth;
    }

    ........ 其他方法 .......
}
英文:

Try out the below sample code snippet for fetching the queue depth.

String mqQMgr = "";
String mqQueue = "";
MQEnvironment.hostname = "";
MQEnvironment.port = "";
MQEnvironment.channel = "";    
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQQueueManager qMgr = new MQQueueManager(mqQMgr);
MQQueue destQueue = qMgr.accessQueue(mqQueue, openOptions);
int depth = destQueue.getCurrentDepth();
destQueue.close();
qMgr.disconnect();

A full code version (Change your parameters accordingly, like Bindings or client mode, options etc ) :

import com.ibm.mq.*;
public class QueueManager {
private final String host;
private final int port;
private final String channel;
private final String manager;
private final MQQueueManager qmgr;
public QueueManager(String host, int port, String channel, String manager) throws MQException {
this.host = host;
this.port = port;
this.channel = channel;
this.manager = manager;
this.qmgr = createQueueManager();
}
private MQQueueManager createQueueManager() throws MQException {
MQEnvironment.channel = channel;
MQEnvironment.port = port;
MQEnvironment.hostname = host;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
return new MQQueueManager(manager);
}
// This method will return the Queue Depth
public int queueDepth(String queueName) {
int depth = -1;
int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue queue = null;
try {
queue = qmgr.accessQueue(queueName, openOptions);
depth = queue.getCurrentDepth();
}
catch (MQException e)
{
System.out.println("CC=" +e.completionCode + " : RC=" + e.reasonCode);
}
finally {
try {
if (queue != null)
queue.close();
}
catch (MQException e) {
System.out.println("CC=" +e.completionCode + " : RC=" + e.reasonCode);
}
}
return depth;
}
........ Other Methods .......
}

huangapple
  • 本文由 发表于 2020年7月30日 17:29:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63170198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定