Skip to content

Improve reconnection #52

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

Merged
merged 9 commits into from
Mar 11, 2025
Merged

Improve reconnection #52

merged 9 commits into from
Mar 11, 2025

Conversation

DanielePalaia
Copy link
Contributor

@DanielePalaia DanielePalaia commented Feb 26, 2025

This PR improves the remote disconnection management, implementing a full automatic reconnection:

  • We remove the disconnection callback management from the user and this is now done internally to the client. The connection keeps track of managements, publishers and consumers and when detect a disconnection reconnect the Connection with relative managements, publishers and consumers handlers.
  • In case of streams we continue Consuming from the last saved Consumed offset
  • BackOff Interval and max_retry are configurable parameters when reconnecting
  • Example scenarios have been updated accordingly as well as README

@DanielePalaia DanielePalaia marked this pull request as draft February 26, 2025 14:26
@DanielePalaia DanielePalaia force-pushed the improve_reconnection branch 2 times, most recently from 314af4c to 9b5d355 Compare March 5, 2025 09:13
@DanielePalaia DanielePalaia force-pushed the improve_reconnection branch 2 times, most recently from 9f12f1c to e8b0683 Compare March 5, 2025 09:52
@DanielePalaia DanielePalaia force-pushed the improve_reconnection branch from e8b0683 to c09162d Compare March 5, 2025 10:09
@DanielePalaia DanielePalaia self-assigned this Mar 7, 2025
@DanielePalaia DanielePalaia marked this pull request as ready for review March 7, 2025 09:16
@@ -86,7 +87,7 @@ def main() -> None:
queue_name = "example-queue"

print("connection to amqp server")
environment = Environment("amqp://guest:guest@localhost:5672/")
environment = Environment("amqp://guest:guest@localhost:5672/", reconnect=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of reconnect=True, I would use something like:
https://github.com/rabbitmq/rabbitmq-amqp-go-client/blob/d84c3d22de34b767e55e68e4f0fc54137b506924/pkg/rabbitmqamqp/amqp_connection_recovery.go#L8

RecoveryConfiguration struct {
	/*
		ActiveRecovery Define if the recovery is activated.
		If is not activated the connection will not try to createSender.
	*/
	ActiveRecovery bool

	/*
		BackOffReconnectInterval The time to wait before trying to createSender after a connection is closed.
		time will be increased exponentially with each attempt.
		Default is 5 seconds, each attempt will double the time.
		The minimum value is 1 second. Avoid setting a value low values since it can cause a high
		number of reconnection attempts.
	*/
	BackOffReconnectInterval time.Duration

	/*
		MaxReconnectAttempts The maximum number of reconnection attempts.
		Default is 5.
		The minimum value is 1.
	*/
	MaxReconnectAttempts int

to make the reconnections more configurable

@DanielePalaia
Copy link
Contributor Author

@Gsantomaggio Hey, back to you for final review. I also implemented the backoff and max_attempt!

Copy link
Member

@Gsantomaggio Gsantomaggio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are just a couple ot things.

I would enable the recovery connection by default and also I would validate the values,

for example avoid the recconnetion time < 1 seconds

@DanielePalaia DanielePalaia force-pushed the improve_reconnection branch 2 times, most recently from c25c94a to f599178 Compare March 11, 2025 13:25
@DanielePalaia
Copy link
Contributor Author

@Gsantomaggio Done! Back to you!

@DanielePalaia DanielePalaia merged commit 1165a4d into main Mar 11, 2025
1 check passed
@DanielePalaia DanielePalaia deleted the improve_reconnection branch March 11, 2025 14:41
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