我正在尝试创建一个通信类,它将向 MQ 发送请求并从他们那里获得响应。
以下是我编写的代码。
TextMessage inputMsg = session.createTextMessage(message);
inputMsg.setJMSReplyTo(responseQueue);
try {
connection.start();
sender.send(inputMsg);
messageId = inputMsg.getJMSMessageID();
reciever = session.createConsumer(responseQueue,"JMSMessageID = '"+messageId+"'");
Message mess=reciever.receive(10000);
TextMessage outputMsg = (TextMessage) mess;
if(outputMsg == null)
logger.error(" Error while recieving the message");
else
replyMsg= outputMsg.getText();
每当执行代码时,此代码都会给我以下对象等待。
java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:167)
at com.ibm.mq.jmqi.remote.internal.system.RemoteProxyQueue.proxyMQGET(RemoteProxyQueue.java:2667)
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiGetMessageWithRecon(RemoteFAP.java:6219)
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiGetMessage(RemoteFAP.java:6112)
at com.ibm.mq.jmqi.internal.JmqiTools.getMessage(JmqiTools.java:1090)
at com.ibm.mq.jmqi.remote.internal.RemoteFAP.jmqiGet(RemoteFAP.java:6080)
at com.ibm.msg.client.wmq.internal.WMQConsumerShadow.getMsg(WMQConsumerShadow.java:1305)
at com.ibm.msg.client.wmq.internal.WMQSyncConsumerShadow.receiveInternal(WMQSyncConsumerShadow.java:239)
at com.ibm.msg.client.wmq.internal.WMQConsumerShadow.receive(WMQConsumerShadow.java:1058)
at com.ibm.msg.client.wmq.internal.WMQMessageConsumer.receive(WMQMessageConsumer.java:469)
at com.ibm.msg.client.jms.internal.JmsMessageConsumerImpl.receiveInboundMessage(JmsMessageConsumerImpl.java:879)
at com.ibm.msg.client.jms.internal.JmsMessageConsumerImpl.receive(JmsMessageConsumerImpl.java:431)
at com.ibm.mq.jms.MQMessageConsumer.receive(MQMessageConsumer.java:228)
但是,如果我将 createConsumer 行更改为,
reciever = session.createConsumer(responseQueue,"JMSMessageID = '"+messageId+"'");
上述行的问题是我的响应消息在更多并发请求期间变得混乱,从而导致会话混淆。
有人可以指导我如何解决这个问题吗?
提前致谢。