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.