[英]Python + STOMP not receiving messages from ActiveMQ
我最近有一項任務是制作可以讀取/接收和顯示來自 ActiveMQ 的消息的 Python 腳本。 它有on_message
和on_error
方法,分別打印“received message...”和“received error...”。 不幸的是,即使它與 ActiveMQ 有連接,也不會打印任何東西。
import time
import sys
import stomp
class ConnectionListener(object):
def on_error(self, message):
print('received an error %s' % message)
def on_message(self, message):
print('received a message %s' % message)
print(message.body)
with open('/usr/ubuntu/result.txt', 'w') as txt_file:
txt_file.write(str(message))
conn = stomp.Connection(host_and_ports=[('localhost', 61613)])
conn.set_listener('', ConnectionListener())
conn.connect("admin", "admin", wait=True)
conn.subscribe(destination='/topic/topictest', id='1', ack='auto')
time.sleep(2)
conn.disconnect()
也許問題出在我給的目的地上。 所以我試圖改變destination='/topic/...'
。 什么都沒發生。 我需要我的代碼來顯示消息。
你似乎錯過了:
conn.start()
conn.connect()
方法之前的行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.