Feel free to open an 'Improvement' JIRA Issue - we could emit an ApplicationEvent
when the connection is lost (and re-established); you could then subscribe to that event with an ApplicationListener
.
In the meantime, you could do something via your logging subsystem - for example, with Log4J, you can create a custom appender to get logs with the SimpleMessageListenerContainer
category, such as...
16:05:50.042 WARN [SimpleAsyncTaskExecutor-6][org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: com.rabbitmq.client.ShutdownSignalException: connection error; reason: {#method<connection.close>(reply-code=320, reply-text=CONNECTION_FORCED - broker forced connection closure with reason 'shutdown', class-id=0, method-id=0), null, ""}
16:05:55.048 WARN [SimpleAsyncTaskExecutor-7][org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
EDIT:
There is also a ConnectionListener
interface which you can register an implementation of with the connection factory; you can learn of new connections with it, but onClose()
is currently only called when the connection is explicitly closed by destroying the factory.
However, the onCreate()
gives you a handle to the connection so you could call its isOpen()
method from time to time, but don't do that in the onCreate()
method itself - save off the connection. You must exit the onCreate()
for all to work as planned.