amqp091-go icon indicating copy to clipboard operation
amqp091-go copied to clipboard

Example Client: Implementation of a Consumer with reconnection support

Open andygrunwald opened this issue 3 years ago • 6 comments

example_client_test.go shows a great way how to build a Producer with reconnection support.

The Consuming part is not covering the reconnection support: https://github.com/rabbitmq/amqp091-go/blob/51fade522e4d209b3cef22ff8c052d944524ac17/example_client_test.go#L257-L274

Even if reconnection support is mentioned as a non-goal for the library itself, I do think showcasing this in the example might be a good thing.

Right now, the implementation is only possible with a hack involved. Mainly due to these two issues:

  • https://github.com/rabbitmq/amqp091-go/issues/18
  • https://github.com/rabbitmq/amqp091-go/issues/32

These deadlocks prevent the consumer delivery channel to be closed during an unexpected connection loss (e.g., when the RabbitMQ server goes down).

andygrunwald avatar Jan 21 '22 10:01 andygrunwald

@andygrunwald Now that we understood what happened in https://github.com/rabbitmq/amqp091-go/issues/18 I think the example you propose can be just like an extension to the example we made in the documentation on how to handle channels for NotifyClose to avoid the deadlock for a consumer?

DanielePalaia avatar Apr 07 '22 13:04 DanielePalaia

Yeah, exactly. I was waiting for #18/#32. I have it implemented incl. the deadlock in one of my projects.

If you are good with it, I would make a PR in the next few days and playback my implementation into the example client. Might take a few days.

andygrunwald avatar Apr 07 '22 19:04 andygrunwald

Sure! good enough! Thanks @andygrunwald

DanielePalaia avatar Apr 07 '22 20:04 DanielePalaia

This gives an example of auto-reconnection as well:

https://github.com/rabbitmq/amqp091-go/commit/4ce2c8e4e371338add82c3dc2df56f70d0dca601

lukebakken avatar May 21 '22 15:05 lukebakken

@andygrunwald any updates with your example client?

metalrex100 avatar May 22 '22 17:05 metalrex100

@metalrex100 Still on my list. My client is working in production since quite some time. Will check if I can make some time in the next days to push it back.

andygrunwald avatar May 27 '22 18:05 andygrunwald