Skip to content
Advertisement

Spring JMS(ActiveMQ) delayed delivery of messages

We’re trying to set a delay on some JMS messages, so that a message will only be added to the queue/ received by the listener after x time. So far we’ve tried 2 approaches that didn’t work.

1) According to the spring documentation, we can set the delivery delay on the JMSTemplate. This is the sample code we tried:

JavaScript

However, we get the following exception, even though our spring jms version is 4.0.5:

JavaScript

2) We also tried setting the delay on the message itself, but it looks like the delay was ignored, and the message was delivered immediately anyway.

JavaScript

The jmsTemplate definition in the spring xml:

JavaScript

Does anyone has any suggestions on what the problems are / other ideas on how to achieve delayed messaging? Thanks!

Advertisement

Answer

The comments give the answer. By default scheduled message support is disabled. You must enabled it in the broker XML configuration file as mentioned on the documentation page.

An example Broker tag with scheduler support enabled:

JavaScript

You must of course restart the broker in order for configuration changes to take affect. Then when you send a message you need to add the JMS headers that tell the broker what type of delay you want.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement