Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

How to consume / handle multiple messages simultaneously? #85

Closed datakurre closed 8 years ago

datakurre commented 8 years ago

With a single connection and a single channel I am unable to handle more than one simultaneous message.

Am I missing something?

If I create multiple connections, I'm able to simultaneously consume one message per connection (thus, 10 connections give 10 simultaneously handled messages). This also confirms that my handler code is not blocking asyncio from that.

datakurre commented 8 years ago

Resolved. I must wrap my consuming callback to instantly returning asyncio.ensure future to free aioamqp to receive more messages.

dzen commented 8 years ago

hello @datakurre,

Yes absolutely. You have to be in an asyncio context. In the same way that this example (https://compiletoi.net/fast-scraping-in-python-with-asyncio/) uses asyncio.wait() you probably have to use Tasks ;)

Remember that you can still get one connection and multiple channels.