【问题标题】:Stomp listeners are dropping after some time but program is running without showing any errors一段时间后,Stomp 监听器正在下降,但程序正在运行而没有显示任何错误
【发布时间】:2021-10-08 13:14:39
【问题描述】:

我在 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()

【问题讨论】:

    标签: python activemq stomp stomp.py


    【解决方案1】:

    由于您没有使用 STOMP heart-beating,因此您的应用程序不会检测到死连接也就不足为奇了。

    您可以像这样配置心跳:

    conn = stomp.Connection([('localhost', 61613)], heartbeats=(4000, 4000))
    

    有关详细信息,请参阅stomp.py documentation

    【讨论】:

    • 感谢您的回复。我试过这个,但是在添加心跳之后,我的消费者开始频繁地连接和断开连接。(准确地说是每 12 秒)。我在心跳中使用了 4000,4000。
    • 这向我表明心跳正在失败。你知道为什么心跳会失败吗?
    • AcitveMQ 服务器一直处于启动状态。我真的不知道为什么会失败。是否还有其他原因。谢谢。
    • 网络延迟或故障可能会导致此问题以及代理的繁重负载。我敢肯定还有其他潜在原因,但这些最有可能是我想不到的。
    猜你喜欢
    • 2020-07-23
    • 2021-09-22
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 2011-07-24
    相关资源
    最近更新 更多