我在 Activemq 队列上有一个 stomp 侦听器,它在启动一段时间后会自行丢弃。程序本身没有显示错误并显示为运行状态,但 Activemq UI 上列出的侦听器在一段时间后仅显示 0。我正在使用此代码
class MyListener(stomp.ConnectionListener):
def __init__(self, conn):
self.conn = conn
self.msg = []
def on_error(self, frame):
print('received an error "%s"' % frame.body)
def on_message(self, frame):
print('received a message "%s" from queue' % frame.body)
headers = frame.headers
self.conn.ack(id=headers["message-id"], subscription=headers["subscription"])
def on_disconnected(self):
print('disconnected')
connect_and_subscribe(self.conn)
def main():
conn = stomp.Connection([('localhost', 61613)])
a = MyListener(conn)
conn.set_listener('', a)
connect_and_subscribe(conn)
try:
while True:
if not conn.is_connected():
print('disconnected... connecting again')
connect_and_subscribe(conn)
time.sleep(5)
except KeyboardInterrupt:
print('interrupted - so exiting!')
conn.disconnect()