英文:
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 .......
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论