【发布时间】:2016-11-23 21:20:26
【问题描述】:
我当前的应用程序逻辑使用“PROCESS”WMQ 队列的深度来确定 IIB9 工作流是否正在处理作业。如果工作流正在处理消息,则应用程序会等待该工作流结束。工作流结束后,“PROCESS”队列将使用 GET 操作清空,应用程序将按顺序发送其他消息进行处理。我正在使用 JMS 选择器来区分工作流并行处理的多条消息。
问题在于确定队列的深度。 JMS API 将深度设为 0,而 IBM API 将深度设为 1(这是预期的)。不幸的是,我不能使用 IBM API 作为我的逻辑,使用一些复杂的消息选择器。
有人见过这种奇怪的行为吗?请注意,在进行大小检查时,IIB9 工作流程正在进行中。有什么需要调整的设置吗?
JMS 代码(为清楚起见删除了消息选择器):
public class QDepthJMS {
public static void main(String[] a) throws Exception {
MQConnectionFactory factory = new MQConnectionFactory();
factory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
factory.setQueueManager("QM01");
factory.setHostName("10.10.98.15");
factory.setPort(1414);
factory.setChannel("Java.Clients");
MQConnection connection = (MQConnection) factory.createConnection();
connection.start();
MQSession session = (MQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///PROCESS");
MQQueueBrowser browser = (MQQueueBrowser) session.createBrowser(queue);
Enumeration<Message> msgs = browser.getEnumeration();
int count =0;
if (msgs.hasMoreElements()) {
msgs.nextElement();
++count;
}
System.out.println(count);
}
}
IBM API (Check MQ queue depth):
public class QDepth {
private final String host;
private final int port;
private final String channel;
private final String manager;
private final MQQueueManager qmgr;
public QDepth(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();
}
public int depthOf(String queueName) throws MQException {
MQQueue queue = qmgr.accessQueue(queueName, MQC.MQOO_INQUIRE | MQC.MQOO_INPUT_AS_Q_DEF, null, null, null);
return queue.getCurrentDepth();
}
@SuppressWarnings("unchecked")
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 static void main(String[] a) throws Exception {
QDepth qd = new QDepth("10.10.98.15, 1414, "Java.Clients", "QM01");
System.out.println(qd.depthOf("PROCESS"));
}
}
【问题讨论】: