1

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?

Punter Vicky
  • 15,954
  • 56
  • 188
  • 315

1 Answers1

2

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.

Guerry
  • 739
  • 4
  • 10
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks @Gary Russel. Could RetryTemplate be used by the consumer which is consuming the messages from RabbitMQ. I have 10 consumers setup for each app instance and I see them continuously trying to connect to rabbitmq instance which is down. Is there a way for me to use either retrytemplate or circuitbreaker to stop polling the queue? – Punter Vicky Feb 22 '17 at 23:00
  • No; on the consumer side, you can configure the connection retries via the `recoveryInterval` or `recoveryBackOff`. If you use a `FixedBackOff`, it can be configured with `maxAttempts` and it will stop the container automatically after that number. You would have to start the containers again manually when the connection is fixed. – Gary Russell Feb 22 '17 at 23:36
  • Thanks @Gary Russell. – Punter Vicky Feb 23 '17 at 00:12