I have a Spring Boot app that sits between an upstream RabbitMQ broker and a downstream REST service. It reads messages from a queue in the upstream broker and posts data from the message to the downstream REST service
For reading the messages I'm using the @RabbitListener
annotation
I have a scheduled check for health of the REST service. If it is not available, I would like to stop reading messages from the RabbitMQ queue. I've a feeling it might require customising the RabbitListenerContainer, but I'm not sure if this is correct or where to start
Any help on configuring message consumption only while a condition is met would be much appreciated
CodePudding user response:
Get a reference to the container from the RabbitListenerEndpointRegistry
infrastructure bean (give the listener(s) an id
).
You can then stop/start the container(s) as needed.