gpt4 book ai didi

python - 使用 stomp.py 时,AMQ_SCHEDULED_DELAY 不会延迟消息

转载 作者:行者123 更新时间:2023-11-30 22:38:19 30 4
gpt4 key购买 nike

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

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

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

输出:

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"

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

最佳答案

通过在 activemq.xml 中将代理调度程序支持属性设置为 true 来启用它:

<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

关于python - 使用 stomp.py 时,AMQ_SCHEDULED_DELAY 不会延迟消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43620262/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com