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

2024-10-03 21:26:57 发布

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

我使用链接http://10.41.248.10:8161/admin/queues.jsp访问队列(activemq)。我想读队列里的留言名称:Notificationqueue。我想用Python和跺脚。队列的用户名和密码是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()

当我运行这个时,我得到了错误

^{pr2}$

一。请尽早帮助完成此代码。如果你需要更多的信息,一定要问我


Tags: 代码importself名称messageadmintime队列
1条回答
网友
1楼 · 发布于 2024-10-03 21:26:57

在连接到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不用于二手踏板。我有一个类似的问题,但在更改端口号后,我没有得到连接失败异常。在

相关问题 更多 >