Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

handling disconnection/reconnection logic #169

Closed alonisser closed 5 years ago

alonisser commented 6 years ago

I've failed to find where and how I can gracefully handle disconnection from rabbitmq instance. Currently when I shutdown rabbitmq after connecting, allow keepalive to fail, I don't see automated reconnection after rabbitmq is online again

chibby0ne commented 5 years ago

What happened with this issue? Is this something that will eventually come?

RemiCardona commented 5 years ago

a simple while loop is what you need to reconnect to your rabbit server. We don't intended to provide this feature as it's a high-level operation that's out of the scope of aioamqp.

Just an example, on one of our internal project, we need to do a whole bunch of operations if/when the amqp connection goes away and the API to handle our needs would be extensive. So we do a while loop. Something along those lines:

while True:
    transport, protocol = await aioamqp.connect(...)
    # here, launch tasks that we use 'protocol' and actually do work
    await protocol.wait_closed()
    transport.close()
    # clean-up of previously launched tasks goes here

HTH