Ousama Hejazi Ousama Hejazi - 4 months ago 18
Java Question

how to send msg to Websphere MQ with specific reply to MQ MGR using JMS

I need to build a java standalone application with ability to send messages to MQSeries specifying reply-to queue and reply-to MQMgr.
I was able to use the code in SimpleP2P example to send a message, but unable to specify the reply-to queue and reply-to MQMgr

public static void main(String[] args) {
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();




cf.setHostName("xyz.com");
cf.setPort(141600);
cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
cf.setQueueManager("QMG");
cf.setChannel("CHANNEL");


MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///A.QUEUE");
MQQueueSender sender = (MQQueueSender) session.createSender(queue);

long uniqueNumber = System.currentTimeMillis() % 1000;
String fileText = convertXMLFileToString("test.xml");
System.out.println("fileText "+fileText);

JMSTextMessage message = (JMSTextMessage) session.createTextMessage(fileText);


connection.start();

System.out.println("before Sent message:\\n" + message);

sender.send(message);
System.out.println("Sent message:\\n" + message);

sender.close();

session.close();
connection.close();

System.out.println("\\nSUCCESS\\n");
}
catch (JMSException jmsex) {
System.out.println(jmsex);
System.out.println("\\nFAILURE\\n");
}
catch (Exception ex) {
System.out.println(ex);
System.out.println("\\nFAILURE\\n");
}
}

Answer

Try this:-

MQQueue replyToQ = new MQQueue(QMgrName, ReplyQueue);
Destination replyTo = (Destination) replyToQ;
message.setJMSReplyTo(replyTo);
Comments