如何使用python和STOMP从Activemq队列中读取消息

时间:2018-09-03 14:56:23

标签: python activemq stomp

我使用链接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

。请帮助尽快完成此代码。请问我是否需要更多信息

1 个答案:

答案 0 :(得分:0)

连接到activemq时,需要提供STOMP端口61613 http://activemq.apache.org/stomp.html)

transportConnector名称=“ stomp” uri =“ stomp:// localhost:61613”

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

端口61616不适用于二手STOMP。我遇到了类似的问题,但是更改端口号后,我没有出现连接失败异常。