3

The RabbitMQ documentation presents how to add a shutdown listener and when the listener is called but I fail to see on what purpose the handler is for. Seems that all the Java examples (including https://github.com/rabbitmq/rabbitmq-tutorials) out there ignore shutdown handlers. In which cases should I prefer shutdown listener over simply catching ShutdownSignalException (and IOException) exception ?

Another puzzling issue is that where the control flow goes when the handler has finished.

Potentially relevant related SO questions:

Community
  • 1
  • 1
user272735
  • 10,473
  • 9
  • 65
  • 96

1 Answers1

2

The main use of a ShutdownListener i've seen is to do automatic reconnection. You listen for a shutdown, and when it happens, try to reconnect.

For example, this is the basis of rabbitmq-ha-client, where it is done in HaConnectionFactory.HaShutdownListener.

Tom Anderson
  • 46,189
  • 17
  • 92
  • 133