Open alexgarel opened 9 years ago
Any update on this?
Trying to figure out how to use Kombu in async way in a Tornado IO Loop
@avinassh the code above is for Tornado, with a class like this:
class BrokerClient(object):
def __init__(self):
self.connection = Connection("<broker_url>")
# use tornado io_loop
pc = ioloop.PeriodicCallback(self._handle_loop, 1)
self.events_poller = self.events_poller_generator()
pc.start()
httpserver.HTTPServer(application).listen(options.port)
And the above methods. Then to start it:
io_loop = ioloop.IOLoop.instance()
BrokerClient()
io_loop.start()
Note: this is code stripped down from a larger program, not sure if I didn't miss somethings, but this should give you good indications.
Thanks @alexgarel! I will try that code and report back here :D
tl;dr: ConsumerMixin can't be used in a framework using continuations. Could it be that kombu add an option for consume tu yield in such cases, this would make integration lighter ?
We use kombu to poll events from amqp in a Tornado websocket. For this I need to use a generator wich can be called as a continuation on every ioLoop, non blocking if there are no events.
Our first attempt was to use the ConsumerMixin this way:
The problem here is that consume will create/open/close a new connection each time.
Then we tried to remove the timeout. The problem is that the call is blocking until an event arrive.
The consume method of ConsumerMixin is:
If the consume method would yield on a socket.timeout. (after
conn.heartbeat_check()
) the first attempt would work.Could it be that kombu add an option for consume tu yield in such cases, this would make integration lighter.
For now we have to re-implement this method (and finally we didn't use consumer mixin, instead we go with: