-
-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recovery from network failures #288
Comments
From my experiments it seems I can detect when the connection with the broker is lost because my consumers will receive a
but I would then have to figure out how to re-establish that connection afterwards (in particular if using Another possible hook seems to be |
There is currently no auto-reconnection feature in lapin, indeed. Splitting the AMQP stuff in its own async fn and using the on_error hook to re-spawn it is the best way to handle this atm, I think. As it's usually quite easy to do just that, and adding automatic recovery can add a lot of complexity, there hasn't been any plan to implement such a thing yet, but we could explore this idea at some point |
Thanks a lot for the advice! I noticed that dropping a connection does not affect the behavior of channels - they keep working fine, including their consumers. When is the connection closed? If all channels on top of it are dropped? Does it always need to be closed explicitly? |
Since 1.0, channels are closed once their last reference is dropped, unless they have been manually closed before. |
Amazing, thank you 👍 |
Is there any demo ? |
Well, it's not trivial, and the problem is inherent to the AMQ protocol. WRT basic_publish:
There is no proper way of "resuming" an AMQP session. Other caveat, basic_consume: What most clients do is basically keep some kind of topology descriptor around, and just redeclare the queues and the consumers, leaving all the rest to you, but that can lead to very awkward situations like this and it has bitten me several times in the past, that why as of now I didn't want to implement something that people will expect to "just work" when things are really not that simple and some things just aren't possible to handle automatically. All of these and more examples should definitely be somewhere in the documentation |
I agree that examples showing how to register an That's what I'm trying, but I'm stumped right at the first step - |
I know that people use on_error for this but haven't actually used it this way myself (I use it to just crash the program and have systemd restart it). Here is one way to handle reconnections: https://github.com/CleverCloud/lapin/blob/lapin-1.x/examples/reconnect.rs Sample output with example started without rabbitmq running, then starting rabbitmq, then restarting rabbitmq:
|
FYI, I just landed #311 which basically allows you to save your current topology (exchanges, queues, consumers) and load it back from a json or such (documentation incoming). With this in place, we just need a way for a failed connection to "absorb" a new one (so that streams etc stay the same as before) to get proper automatic reconnection working. |
Now tracked in #312 |
I was browsing the crate to understand if there is any form of automatic recovery when a network failure occurs (similar to what is provided by the .NET client here).
If not, is this something you'd be interested to integrate into
lapin
or do you want to keeplapin
as thin of a client as possible?The text was updated successfully, but these errors were encountered: