Punter Vicky
Punter Vicky

Reputation: 16982

Spring Boot - RabbitMQ - Handle Scenario where broker is down

We use rabbitmq for messaging in our project. This is primarily used for audit logging. We were trying to check how our app responds to certain failure scenarios. For instance if RabbitMQ is down , the consumer continuously attempts to make a connection to rabbitmq and fails. Is there a way for consumer to stop attempting this if rabbitmq is down? In a similar way , how can publisher stop attempting to send messages to the queue when the broker is down? Is circuit breaker one of the options that we can consider?

Upvotes: 1

Views: 1550

Answers (1)

Gary Russell
Gary Russell

Reputation: 174494

You can add a RetryTemplate to the RabbitTemplate bean.

Add a RecoveryCallback implementation to the retry template that just ignores (or logs) the error.

It will attempt to connect, but not fail.

If you use the Spring Integration layer on top of Spring AMQP you can add a circuit breaker request handler advice to the outbound channel adapter.

Upvotes: 2

Related Questions