使用Java获取MQ队列的ClusterName [英] Get ClusterName of MQ Queue using Java
问题描述
我正在构建一个Java应用程序,该应用程序连接到MQQueueManager并提取有关队列的信息.我可以获取诸如QueueType
,MaximumMessageLength
之类的数据.但是,我也想要队列可能在其中的集群的名称.MQQueue附带没有提供此信息的函数.在互联网上搜索后,我发现有几件事指向这个方向,但没有示例.
I'm building a java application that connects to a MQQueueManager and extracts information about queues. I'm able to get data like QueueType
, MaximumMessageLength
and more. However, I also want the name of the cluster the queue might be in. There is no function that comes with the MQQueue that gives me this information. After searching the internet I found several things pointing in this direction, but no examples.
为我提供MaximumDepth
的功能的一部分是:
A part of my function that gives me the MaximumDepth
is:
queueManager = makeConnection(host, portNo, qMgr, channelName);
queue = queueManager.accessQueue(queueName, CMQC.MQOO_INQUIRE);
maxQueueDepth = queue.getMaximumDepth();
(此处未显示makeConnection
,它是与QueueManager进行实际连接的功能;我也省略了try/catch/finally以减少混乱)
(makeConnection
is not shown here, it is the function that makes the actual connection to the QueueManager; I also left out the try/catch/finally for less clutter)
如何获取ClusterName
以及其他可能没有queue.getMaximumDepth()
功能的数据?
How do I get ClusterName
and perhaps other data, that doesn't have a function like queue.getMaximumDepth()
?
推荐答案
经过更多研究,我终于找到了我想要的东西. IBM的此示例:在WebSphere MQ类中获取和设置属性值帮助我设置了查询.
After more research I finally found what I was looking for. This example of IBM: Getting and setting attribute values in WebSphere MQ classes helped me to set up the inquiry.
The necessary values I found in this list: Constant Field Values.
我还需要扩展accessQueue()
的openOptionsArg
,否则无法查询群集队列.
I also needed to expand the openOptionsArg
of accessQueue()
, else cluster queues cannot be inquired.
最终结果:
(没有makeConnection()
)
public class QueueManagerServices {
final static int MQOO_INQUIRE_TOTAL = CMQC.MQOO_FAIL_IF_QUIESCING | CMQC.MQOO_INPUT_SHARED | CMQC.MQOO_INQUIRE;
MQQueueManager queueManager = null;
String cluster = null;
MQQueue queue = null;
public String getcluster(String host, int portNo, String qMgr, String channelName){
try{
queueManager = makeConnection(host, portNo, qMgr, channelName);
queue = queueManager.accessQueue(queueName, MQOO_INQUIRE_TOTAL);
int MQCA_CLUSTER_NAME = 2029;
int MQ_CLUSTER_NAME_LENGTH = 48;
int[] selectors = new int[1];
int[] intAttrs = new int[1];
byte[] charAttrs = new byte[MQ_CLUSTER_NAME_LENGTH];
selectors[0] = MQCA_CLUSTER_NAME;
queue.inquire(selectors, intAttrs, charAttrs);
cluster = new String (charAttrs);
} catch (MQException e) {
System.out.println(e);
} finally {
if (queue != null){
queue.close();
}
if (queueManager != null){
queueManager.disconnect();
}
}
return cluster;
}
}
这篇关于使用Java获取MQ队列的ClusterName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!