AMQ_SCHEDULED_DELAY在使用时不延迟消息跺脚.py

2024-05-15 04:41:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在docker容器上运行ActiveMQ服务器。在

我正在使用AMQ_SCHEDULED_DELAY头来延迟消息。在

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()

输出:

^{pr2}$

从输出来看,它似乎不起作用,或者我必须从ActiveMQ端更新一些东西。在


Tags: importmessagetimeondefsysconnheaders
1条回答
网友
1楼 · 发布于 2024-05-15 04:41:34

在中,通过将broker schedulerSupport属性设置为true来启用它活动MQ.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

相关问题 更多 >

    热门问题