jasonrbriggs / stomp.py

“stomp.py” is a Python client library for accessing messaging servers (such as ActiveMQ or RabbitMQ) using the STOMP protocol (versions 1.0, 1.1 and 1.2). It can also be run as a standalone, command-line client for testing.
Apache License 2.0
491 stars 167 forks source link

Make the receiver thread part of the transport class #435

Open CameronDevine opened 1 month ago

CameronDevine commented 1 month ago

In some applications, the main thread has no work to do after the connection is initiated. This can lead to a while loop such as,

from stomp import *
c = Connection([('127.0.0.1', 62613)])
c.set_listener('', PrintingListener())
c.connect('admin', 'password', wait=True)
c.subscribe('/queue/test', 123)
while True:
    pass

which is inefficient. If the thread is part of the transport class, the following can be written instead,

from stomp import *
c = Connection([('127.0.0.1', 62613)])
c.set_listener('', PrintingListener())
c.connect('admin', 'password', wait=True)
c.subscribe('/queue/test', 123)
c.transport.receiver_thread.join()