Reputation: 185
I try to receive the message from the MQ. I can able to see the messages in the MQ Explorer. But i cant able to get the messages. It always return null. But i can able to drop message to the Queue.
The code is here.
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setHostName("localhost");
cf.setPort(1415);
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setQueueManager("TEST");
cf.setChannel("TEST.CHANNEL");
MQQueueConnection connection = (MQQueueConnection)cf.createQueueConnection("mqusr","q@789945");
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue replyQueue = (MQQueue) session.createQueue("queue:///TEST.REPLY.QUEUE");
MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(replyQueue);
TextMessage receivedMessage = (TextMessage) receiver.receive(10000);
String reponseMessage = receivedMessage != null ? receivedMessage.toString() : "";
Upvotes: 0
Views: 962
Reputation: 185
To receive the message you need to issue connection.start() before doing a receive.receive(10000) –
Upvotes: 2