mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.18k stars 186 forks source link

Does RobustConnection handle reconnection and rebuild channels, exchanges, queues, bindings? #536

Open jalvespinto opened 1 year ago

jalvespinto commented 1 year ago

I am starting to learn rabbitmq and I read in the book "RabbitMQ in Action" that I should handle on my consumer the reconnection and rebuilding of resources basically through the use of a while loop and try, exception block. Now, it seems to me that RobustConnection is capable of doing just that automatically. Is that right? tks

Lancetnik commented 1 year ago

@jalvespinto sure! Here _on_close callback triggers a restore function, that triggers some nested functions, and, finally this function, that restores all exchanges and queues. Queues in their turn restore all bindings and consumers by their restore method. So, there no any magic. But, you should be accurate with: all objects to restore are stores as a WeakRefs. So, if your queue or smth was declared in any function and out of scope now, it will not be restored. I had an Issue in my project that reason.