如何使用python stomp.py客户端在activemq中调度延迟消息

如何使用python stomp.py客户端在activemq中调度延迟消息,python,activemq,stomp,Python,Activemq,Stomp,我正在使用访问我的ActiveMQ服务器 我创建了客户端并发送数据。但我必须这么做 我检查了JAVA示例,其中用户可以传递头文件send也将headers作为stomp.py中的参数,但我不知道必须传入哪个键 没有任何延迟标题 尝试了AMQ\u SCHEDULED\u DELAY标题,但似乎不起作用 import time import sys import stomp class MyListener(stomp.ConnectionListener): def on_error(

我正在使用访问我的
ActiveMQ
服务器

我创建了客户端并发送数据。但我必须这么做

我检查了JAVA示例,其中用户可以传递
头文件
send
也将
headers
作为
stomp.py
中的参数,但我不知道必须传入哪个键

没有任何延迟标题

尝试了
AMQ\u SCHEDULED\u 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()
输出:

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"

通过STOMP发送计划消息的值与代理的Java代码中的值的定义相匹配,但作为快速参考,您可以查看ApacheNMS STOMP站点,以获得快速信息

数值如下:

"AMQ_SCHEDULED_DELAY" = delay in milliseconds
"AMQ_SCHEDULED_PERIOD" = repeat period in milliseconds
"AMQ_SCHEDULED_REPEAT" = repeat count
"AMQ_SCHEDULED_CRON" = cron entry such as "0 * * * *"

您好,Tim,但是如果我们在apache中更改它,那么它将应用于所有消息?我只需要发送几条延迟为
的消息,所有其他消息都需要正常执行。我真的不明白你的问题,当你想应用延迟时,你在跺脚消息上放上标题,不确定你问的apache是关于什么的如果我使用
conn.send(…,…,headers={'AMQ_SCHEDULED_delay':10})
然后这将安排我的邮件在
10
秒后发送?延迟设置为毫秒,因此不,它将延迟10毫秒。请确保已在Broker上启用计划程序支持。对于其他读者,是的,您正在做正确的事情。正如下面的讨论,我相信MessageBroker没有启用调度器。
"AMQ_SCHEDULED_DELAY" = delay in milliseconds
"AMQ_SCHEDULED_PERIOD" = repeat period in milliseconds
"AMQ_SCHEDULED_REPEAT" = repeat count
"AMQ_SCHEDULED_CRON" = cron entry such as "0 * * * *"