Search code examples
pythonactivemq-classicdelaystomp.py

AMQ_SCHEDULED_DELAY is not delaying message when use stomp.py


I am running ActiveMQ server on docker container.

I am using AMQ_SCHEDULED_DELAY headers to delay the message.

import time
import sys

import stomp

class MyListener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)
    def on_message(self, headers, message):
        print "Time for message receive: %s", time.strftime('%H:%M:%S')
        print('received a message "%s"' % message)

conn = stomp.Connection()
conn.set_listener('', MyListener())
conn.start()
conn.connect(wait=True)

conn.subscribe(destination='/queue/test', id=1, ack='auto')

print "Time for send message: %s", time.strftime('%H:%M:%S')
conn.send(body=' '.join(sys.argv[1:]), destination='/queue/test', headers={'AMQ_SCHEDULED_DELAY': 100000})

time.sleep(2)
conn.disconnect()

Output:

test@localhost$ python /tmp/test.py this is test
Time for send message: %s 14:03:34
Time for message receive: %s 14:03:34
received a message "this is test"

From output, seems its not working or I have to update something from ActiveMQ side.


Solution

  • It is enabled by setting the broker schedulerSupport attribute to true in the activemq.xml :

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

    http://activemq.apache.org/delay-and-schedule-message-delivery.html