Search code examples
hibernateactivemq-classicxaatomikos

Adding delay on jms message processing


I am using atomikos with Hibernate and ActiveMQ. My transaction involves,message being commited to DB and sent to queue. JMS reveiver then reads the message and calls get from db.

There are cases where Atomikos has commited to Queue but hibernate commit is still in progress , in the mean time get query is fired from receiver.I tried to find if there is way we can specify commit order in XA transaction but answer seems to be no reading this.

So I was thinking is there a way we can add some lag in message processing so that message is icked up only after 5sec by the time commit would have been successful.


Solution

  • activemq support delayed message, see http://activemq.apache.org/delay-and-schedule-message-delivery.html

    2 things you should do:

    first is adding schedulerSupport in activemq.conf

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

    and then add a AMQ_SCHEDULED_DELAY property when sending.

    like textMessage.setLongProperty("AMQ_SCHEDULED_DELAY", 5000);