How to handle jmsTemplate.receive no response case

33 views Asked by At

I'm using jmsTemplate.receive("queueName") to receive data from service bus queue. I'm using it as an API request. One issue I'm facing is if no message left to process from the queue it's not completing the request, not even throwing an error. Is there any way in jmsTemplate to check if no data is to process then it should stop the request.

I tried so many approaches but none works.

1

There are 1 answers

0
Daniel Steinmann On BEST ANSWER

You have to call jmsTemplate.setReceiveTimeout before calling jmsTemplate.receive.

When not set, it waits forever for the next message, as written in the Java doc:

The default is JmsDestinationAccessor.RECEIVE_TIMEOUT_INDEFINITE_WAIT, which indicates a blocking receive without timeout.