We communicate with the third party using IBM MQ in request/reply fashion. We send them request and they give us reply. Current we both have a simple java based native IBM MQ application. We are planning to rewrite our code using spring jms. But we are not getting any response back within given time when spring jms is used. We are using JMSTemplate to send or receive messages. I am sharing my code snippet. Am I doing anything wrong here? Any other properties should I set here?
// Request Part (we are sending request)
String request // this is the request string
byte[] reqData = request.getBytes(); // converting it into byte array to send
TextMessage txtMsg = session.createTextMessage(String.valueOf(reqData));
Destination replyToQName = jmsTemplate.getDestinationResolver().resolveDestinationName(session, responseQueueName, false);
txtMsg.setJMSReplyTo(replyToQName);
Destination requestQ = jmsTemplate.getDestinationResolver().resolveDestinationName(session, requestQueueName, false);
((JmsDestination) requestQ).setBooleanProperty( WMQConstants.WMQ_MQMD_WRITE_ENABLED, true );
((MQQueue) requestQ).setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ); // setting this because third party application is native websphere mq java application
jmsTemplate.convertAndSend(requestQ, txtMsg);
// saved msgId of request for late use
String messageId = txtMsg.getJMSMessageID();
// Response fetching part
Destination responseQ = jmsTemplate.getDestinationResolver().resolveDestinationName(session, responseQueueName, false);
((JmsDestination) responseQ).setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
((JmsDestination) responseQ).setObjectProperty( WMQConstants.JMS_IBM_MQMD_CORRELID, msgIdText);
jmsTemplate.setReceiveTimeout(30000L);
String filter = "JMSCorrelationID='" + messageId + "'"; // to match request message's messageId with response message's correlationId
TextMessage respMsg = (TextMessage) jmsTemplate.receiveSelected(responseQ, filter);
Below is my connectionFactory code:
MQConnectionFactory factory = new MQQueueConnectionFactory();
factory.setHostName("hostname");
factory.setPort(1420);
factory.setQueueManager("QM1");
factory.setChannel("TEST.CHANNEL");
factory.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);