简体   繁体   English

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

[英]How to read messages from Activemq queues using python and STOMP

I access queues(activemq) using the link http://10.41.248.10:8161/admin/queues.jsp .我使用链接http://10.41.248.10:8161/admin/queues.jsp访问队列(activemq)。 I wanted to read the message from the queue name:Notificationqueue.我想从队列名称中读取消息:Notificationqueue。 I wanted to use python and STOMP.我想使用 python 和 STOMP。 The username and password to the queue is admin/admin.队列的用户名和密码是 admin/admin。 Please help me step by step to get the message from queue name:Notificationqueue.请帮助我逐步从队列名称获取消息:Notificationqueue。 Below is my code, please help to complete the code下面是我的代码,请帮助完成代码

#!/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()

When I run this, I get the error,当我运行这个时,我收到错误,

 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

. . Please help in completing this code at the earliest.请尽快帮助完成此代码。 Do ask me if you need more information如果您需要更多信息,请询问我

You need to give the STOMP port 61613 when connecting to activemq http://activemq.apache.org/stomp.html连接activemq时需要给STOMP端口61613 http://activemq.apache.org/stomp.html

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

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

The port 61616 is not for used STOMP.端口 61616 不适用于已使用的 STOMP。 I had a similar issue but after changing the port number I did not get connection fail exception.我有一个类似的问题,但在更改端口号后,我没有收到连接失败异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM