Question

We are currently using JmsTemplate's send(Destination, messageCreator) method for sending messages to webMethods queue. However, there are times that the send method takes too long to return which we cannot afford as our timeout should only be 5 seconds. My question is how can we ensure this? It seems that JmsTemplate has no send timeout.

An option I think we have is to wait for 5 seconds response from send() method. If it elapsed to more than 5 seconds, we will consider it as fail. However, we need to ensure that the message (tried to send) sent will not be processed at all as we'll be considering this request as failed. How do we do this? Rollback? Thanks!

Was it helpful?

Solution

The JmsTemplate is a higher level abstraction over the core JMS API. That core (JMS) API has no such mechanism.

It is quite unusual for a JMS send to take that long; unless you have really huge messages and a slow network.

You could process the send on another thread and try interrupting it after the 5 seconds, but that will only work if the JMS client library code is interruptible.

However, it is generally impossible to do what you want reliably, because of the race condition.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top