Showing posts with label activemq. Show all posts
Showing posts with label activemq. Show all posts

Friday, September 4, 2026

ActiveMQ: AMQ_SCHEDULED_DELAY Not Working Correctly

After implementing the below method, I was able to send the message to the ActiveMQ queue. However, the message delay was not working as expected.

In this example, I have specified the delay as 60000 ms, which is equal to 1 minute.

Example:

public void sendMessage(final String xmlMessage) { try { jmsTemplate.send("Your_Queue_Name", new MessageCreator() { public Message createMessage(final Session session) throws JMSException { Message message = session.createTextMessage(xmlMessage); message.setLongProperty( ScheduledMessage.AMQ_SCHEDULED_DELAY, 60000 ); return message; } }); } catch (Exception e) { // Error occurred while sending message to the queue } }

The message was being delivered immediately through onMessage(), instead of waiting for the specified 1-minute delay.

After further analysis and investigation, I found that scheduler support needs to be enabled in the ActiveMQ broker configuration. Add schedulerSupport="true" to the broker configuration in the `activemq.xm`l file.

File: /conf/activemq.xml

Example:

<broker xmlns="http://activemq.apache.org/schema/core"
        brokerName="localhost"
        dataDirectory="${activemq.data}"
        schedulerSupport="true">

After enabling scheduler support, the AMQ_SCHEDULED_DELAY property can be used to delay message delivery as expected.

Hope this helps if you are facing a similar issue with ActiveMQ scheduled messages.