Stomp listeners are dropping after some time but program is running without showing any errors

566 Views Asked by At

I have a stomp listener on an Activemq queue which just drops itself after being up for a while. The program itself shows no error and shows in running state but listener listed on Activemq UI just shows 0 after some time. I am using this code

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()
1

There are 1 best solutions below

9
On BEST ANSWER

Since you aren't using STOMP heart-beating it's not terribly surprising that your application would not detect the dead connection.

You can configure heart-beating like so:

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

See the stomp.py documentation for more details.