I'm using spring-based application to connect to an IBM MQ server for sending and receiving jms messages. I've set the timeout using the setReceivedTimeout function of the Jmstemplate and I expect some JmsException to be thrown once the configured timeout is breached but the application keeps waiting until the response is received in the response queue. I've tried ranges from 100 milliseconds to 10000 milliseconds but it does not honour my configured timeout, the end-time calculation in the below code is always larger than the configured receiveTimeout value. I'm following the spring doc to set the timeout value :-
public void setReceiveTimeout(long receiveTimeout)
Set the timeout to use for receive calls (in milliseconds). The default is JmsDestinationAccessor.RECEIVE_TIMEOUT_INDEFINITE_WAIT, which indicates a blocking receive without timeout.
I've also enabled tracing for mq client using the below code and confirm that the value is correctly set (when set to 500 millisecond):-
System.setProperty("com.ibm.msg.client.commonservices.trace.status","ON");
mqjavaclient_4909.tc :
00000002 @c1d1ad5 c.i.m.c.j.wmq.internal.WMQGMO(MQGMO)----+----+-d getWaitInterval() getter [500(0x1f4)]
IBM MQ client version :
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq-jms-spring-boot-starter</artifactId>
<version>3.2.4</version>
</dependency>
Jmstemplate Bean definition :
@Bean
public JmsTemplate jmsTemplate() throws JMSException {
var mqQueueConnectionFactory = mqQueueConnectionFactory();
var userCredentialsConnectionFactoryAdapter =
getUserCredentialsConnectionFactoryAdapter(mqQueueConnectionFactory);
var jmsTemplate = new JmsTemplate(userCredentialsConnectionFactoryAdapter);
jmsTemplate.setReceiveTimeout(Long.parseLong(receiveTimeout));
return jmsTemplate;
}
Usage :
System.out.println(start);
var message = (TextMessage) jmsTemplate.sendAndReceive(destinationMq, session -> {
TextMessage textMessage = session.createTextMessage(mqRequest.request());
textMessage.setJMSCorrelationID(mqRequest.correlationId());
textMessage.setJMSReplyTo(getMQ(mqRequest.replyToQueue()));
return textMessage;
});
System.out.println(System.currentTimeMillis() - start);