Closed Skorpyon closed 7 years ago
Hi @Skorpyon,
You've hit one of the major API limitations of aioamqp as it stands today: callbacks.
Here are a few things you should know:
consumer = yield from channel.basic_consume(...)
while True:
body, envelope, props = yield from consumer
<application logic goes here>
Until we manage to get there, creating tasks is a user responsibility to avoid blocking aioamqp's processing loop. So you'll have to call self._loop.create_task(...)
from your own callback. Yes, I understand it doesn't feel right, but it is the best solution.
Hope that helps,
Cheers
Today I was surprized, because aioamqp don't launch message callbacks in async loop.
A little explanations here:
protocol.py
channel.py
So each time, when it got frame, it launch callback and wait until it return result. If you have difficult logic in callback works with DB and do long work, like me, you will be surprized when all your system stuck in one callback and even dont receive new messages from AMQP provider.
You may easy check it with basic example code from spec, just add
asyncio.sleep()
:So, just feed
hello
exchange with hundred messages. You will see, how it print first body and go to sllep for 30 seconds. All next messages will be lost or delayed for unpredictable time.For me I temporary solved it this way: protocol.py
It just create new task in loop for callback, dont wait until it finished and unlock loop for new message.
I'm not very professional in async, maybe exists more elegant way. But right now aioamqp is not usable with this issue.
Really it require deep check for same problems in sending messages and internal logic. I hope you fix it ASAP, because few my projects totally depend from your perfect library. Regards.