【问题标题】:How to read messages from Activemq queues using python and STOMP如何使用 python 和 STOMP 从 Activemq 队列中读取消息
【发布时间】:2019-02-08 15:37:25
【问题描述】:

我使用链接http://10.41.248.10:8161/admin/queues.jsp 访问队列(activemq)。我想从队列名称中读取消息:Notificationqueue。我想使用 python 和 STOMP。队列的用户名和密码是 admin/admin。请帮助我逐步从队列名称:Notificationqueue 中获取消息。下面是我的代码,请帮忙完成代码

#!/usr/bin/env python

import time
import sys
import stomp

class MyListener(object):
    def on_error(self, headers, message):
        print 'received an error %s' % message
    def on_message(self, headers, message):
        print 'received a message %s' % message

conn = stomp.Connection(host_and_ports=[('10.41.248.10', 61616)])
conn.set_listener('', MyListener())
conn.start()
conn.connect("admin","admin",wait=True)
conn.subscribe(destination='queue://Notificationqueue', id = '1', ack='auto')
time.sleep(2)
conn.disconnect()

当我运行它时,我得到了错误,

 No handlers could be found for logger "stomp.py"


    conn.connect("admin","admin", wait=True)
  File "C:\Python27\lib\site-packages\stomp\connect.py", line 164, in connect
    Protocol11.connect(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\stomp\protocol.py", line 340, in connect
    self.transport.wait_for_connection()
  File "C:\Python27\lib\site-packages\stomp\transport.py", line 327, in wait_for_connection
    raise exception.ConnectFailedException()
ConnectFailedException

。请尽快帮助完成此代码。如果您需要更多信息,请询问我

【问题讨论】:

    标签: python activemq stomp


    【解决方案1】:

    连接activemq时需要给STOMP端口61613 http://activemq.apache.org/stomp.html

    transportConnector name="stomp" uri="stomp://localhost:61613"

    conn = stomp.Connection(host_and_ports=[('10.41.248.10', 61613)])
    

    端口 61616 不用于使用 STOMP。我有类似的问题,但更改端口号后,我没有收到连接失败异常。

    【讨论】:

      猜你喜欢
      • 2017-10-10
      • 2017-04-12
      • 1970-01-01
      • 2017-05-05
      • 2012-10-09
      • 1970-01-01
      • 2012-09-03
      • 2018-07-19
      • 1970-01-01
      相关资源
      最近更新 更多