【问题标题】:Producing persistent message using stompest for python使用 stompest for python 生成持久消息
【发布时间】:2015-08-17 22:56:33
【问题描述】:

我无法使用 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

【问题讨论】:

  • 我明白了....client.connect(QUEUE,msg,headers={'persistant':'true'})

标签: python activemq stomp


【解决方案1】:

您必须将发送行更改为:

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

【讨论】:

    【解决方案2】:

    如果您坚持使用,您可能还希望在事务中向您发送消息。

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

    这样,您可以确保所有或没有一组消息最终进入队列。如果在事务块中出现错误,消息将不会提交到队列。阅读消息也是如此。

    【讨论】:

      猜你喜欢
      • 2016-01-27
      • 1970-01-01
      • 2014-02-05
      • 2016-12-30
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 2013-11-30
      相关资源
      最近更新 更多