Azure / go-amqp

AMQP 1.0 client library for Go.
https://github.com/Azure/go-amqp
MIT License
104 stars 56 forks source link

Question: Reconnect / retry mechanism #295

Open DGuhr opened 1 year ago

DGuhr commented 1 year ago

Hi 👋

I have a question, as I could not find a reconnect/retry mechanism for this client yet. Is it planned to add a reconnect / retry mechanism, or do you have an example of a consumer that has a reconnect/retry mechanism?

Context:

I searched a bit for such thing, but all I found so-far is https://github.com/isayme/go-amqp-reconnect/blob/master/rabbitmq/rabbitmq.go which is for an amqp 0.9.1 client - and now due to the lack of results, I am questioning myself if we're completely on the wrong track here and there is a hidden mechanism we just don't know of 😅

Thanks!

jhendrixMSFT commented 1 year ago

@richardpark-msft and I have discussed this in the past, but nothing has been implemented in this module yet.

We do have retry/reconnect logic in our EventHubs and Service Bus modules. Here are a few links to the implementation in Service Bus. Note that some of the error conditions are specific to Service Bus, so if you're using a different broker then some of the logic won't apply.

Retry loop for sending/receiving a message Predicate for determining recovery kind

Conceptually it's not that different from your retry/reconnect mechanism. Wait for a message and if an error is received, determine if it requires a reconnect (you should add *amqp.SessionError to your list of reconnect errors).

richardpark-msft commented 1 year ago

@DGuhr, I can't speak for why other libraries don't have retries, but some things in Azure this more complicated.

For instance:

In the end most of our example designs just ended up having to be so general that it just ended up being more straightforward to handle it on a per-call-site basis.

BTW, if you do find that hidden mechanism PLEASE LET US KNOW. :)