Spring RabbitMQ - How to perform application recovery, on RabbitMQ reconnection
I connect to RabbitMQ through a CachingConnectionFactory. This has a simple, built in - forever retry mechanism to recover.
To support dynamic queue management (creation, listening via API), I manipulate the RabbitListenerEndpointRegistry registry;
When the connection to RabbitMQ is interrupted (any network outage), the recovery mechanism is successful. However, the registry is initialized, by Spring.
I have been unable to find a place to hook into the reconnection flow, such that I can rebuild my registry on reconnection. The registry is leveraged by a single @RabbitListener
Where can I execute my own recovery function, eg
dbDao.getActiveQueues().forEach(queueName -> getMessageListenerContainerById(RECEIVED_FROM_CLIENT).addQueueNames(queueName));
8 Replies
⌛
This post has been reserved for your question.
Hey @Jack9! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Maybe something added as an annotation to the
@RabbitListener(id = RECEIVED_FROM_CLIENT, autoStartup = "true", containerFactory = "rabbitListenerContainerFactory")
Then defined:
@Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
ConnectionFactory connectionFactory,
ObjectMapper objectMapper
This message has been formatted automatically. You can disable this using
/preferences
.@Jack9 Have you tried to listen to ConnectionRecoveredEvent?
You can rebuild your registry in the listener
it's called connectionlistener or snth afaik remember
Ugh I am in my bed rn otherwise I'd have checked it out for you
I gave it a try. No dice.
These functions do not trigger on recovery.
This message has been formatted automatically. You can disable this using
/preferences
.Maybe I need a diff version with @EventListener, but I have nothing to go on
The ConnectionEventListener interface is only for connectionClosed() and connectionErrorOccurred()
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
The answer is:
@Component
This message has been formatted automatically. You can disable this using
/preferences
.Post Closed
This post has been closed by <@374014726348210176>.