Skip to content
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

Auto reconnect in case of connection loss #58

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fillson-shady
Copy link
Collaborator

Automatically try to reconnect if connection is interrupted.
Note that if a queue name is not specified then all messages arrived during reconnecting will be lost.
If the queue name is set then messages will be store there and delivered after reconnection.

@fillson-shady fillson-shady requested a review from ghokun September 4, 2024 09:51
@ghokun
Copy link
Owner

ghokun commented Sep 4, 2024

This will take me some time to review. Just a quick look, we may need an exponential backoff to retry connection.

@fillson-shady
Copy link
Collaborator Author

Of course, take your time!
Regarding the backoff - by default a rabbit client will wait for 30 seconds before retrying. So it won't spam a RabbitMQ cluster.
On the other hand we can think of lowering this 30 seconds timeout to 1 second for example (to be able to reconnect ASAP). Then the backoff strategy will be required for sure. WDYT?

@ghokun
Copy link
Owner

ghokun commented Sep 4, 2024

@fillson-shady fillson-shady force-pushed the vfilatov/auto-reconnect branch from f780078 to 8d16c62 Compare September 12, 2024 16:39
@fillson-shady fillson-shady force-pushed the vfilatov/auto-reconnect branch from 8d16c62 to 3472e76 Compare September 12, 2024 16:45
@fillson-shady
Copy link
Collaborator Author

Hi @ghokun, I performed some refactoring, extracted client to a separate file and added a simple backoff strategy to reconnection logic. Thank you for the provided example, it helped a lot!

@fillson-shady fillson-shady force-pushed the vfilatov/auto-reconnect branch from 3472e76 to a72bef4 Compare September 12, 2024 16:49
client.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants