Spring amqp: shutdown detection and reconnection to another queue

We have this setting, where we call the web service to create the queue and get the queue name from the response.

Then we create a SimpleMessageListenerContainer and set the queue name there, and then run it.

However, the queue is deleted from time to time - as a result, error 404 cannot announce error XXXXXXXXX. In these cases, I need to call the web service again and add a new QueueName to SimpleMessageListenerContainer and then delete the old one.

The only way I understood to run any code for processing was to create a custom CachedConnectionFactory and override the shutdownCompleted method.

However, shutdownCompleted seems to fire when the SimpleMessageListenerContainer also switches, so it loops in a loop. The ShutdownSignalException thrown to shutdownCompleted does not seem to look different if the trigger is external from the server or with the client processing the new queue, so I cannot figure out how to skip processing during the "second" transition.

So, what is the usual way to detect and start user processing when the server kills the queue?

0
spring-amqp
source share
1 answer

The container emits a ListenerContainerConsumerFailedEvent when the listener fails.

Add ApplicationListener<ListenerContainerConsumerFailedEvent> , stop the container, change the queues and restart.

You will likely get several events, because by default the container will try to reconnect 3 times before giving up and stopping itself.

0
source share

All Articles