使用stompest for python生成持久消息

2024-06-11 06:45:51 发布

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

我无法使用stompest和python向AMQ队列发送持久消息。。不知道该用什么标题??? 下面是源代码

from stompest.config import StompConfig
from stompest.sync import Stomp
import os

CONFIG = StompConfig('tcp://localhost:61613')
QUEUE = '/queue/myQueue'


if __name__ == '__main__':

    try:
        client = Stomp(CONFIG)
        client.connect({'login':'#####','passcode':'#####'})
        for i in range(10):
            msg="Test Message" +str(i)
            client.send(QUEUE,msg)
        client.disconnect()
    except Exception,e:
        print e

Tags: fromimportclientconfig消息标题源代码队列
2条回答

您必须将发送线路更改为:

client.send(QUEUE,msg, headers={'persistent' :'true'})

如果要持久化,您可能还希望在事务中向您发送消息。在

with client.transaction(receipt='important') as transaction:
        client.send(QUEUE, 'test',{'persistent':'true', StompSpec.TRANSACTION_HEADER: transaction})

通过这种方式,您可以确保一组消息全部或无一结束在队列中。如果在事务块中引发错误,则不会将消息提交到队列。阅读信息也是如此。在

相关问题 更多 >