Tuesday, 3 November 2015

AMQ_SCHEDULED_DELAY not working correctly


AMQ_SCHEDULED_DELAY not working correctly


After the below method implemenation , I am able to send the message to the ActiveMQ queue. But, the delay period is not working correctly.

Here I have the mentioned the delay period as 60000 ms (i.e. 1 mins).


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 occured :: Sending to queue failed "
        }
    }

The message is throwing immidiatly via onMessage(). It means the message is not taking the  ScheduledMessage.AMQ_SCHEDULED_DELAY for my specified message.
After subsequent analysis and investigation , I found we need to configure the schedulerSupport="true" in broker.



Add schedulerSupport="true" in the broker config file (/conf/activemq.xml).

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

Hope it will help you.