简体   繁体   English

Spring Boot - RabbitMQ - 处理代理关闭的场景

[英]Spring Boot - RabbitMQ - Handle Scenario where broker is down

We use rabbitmq for messaging in our project.我们在项目中使用rabbitmq 进行消息传递。 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.例如,如果 RabbitMQ 是 down ,消费者会不断尝试与 rabbitmq 建立连接并失败。 Is there a way for consumer to stop attempting this if rabbitmq is down?如果rabbitmq关闭,消费者有没有办法停止尝试? 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?断路器是我们可以考虑的选项之一吗?

You can add a RetryTemplate to the RabbitTemplate bean.您可以将RetryTemplate添加到RabbitTemplate bean。

Add a RecoveryCallback implementation to the retry template that just ignores (or logs) the error.RecoveryCallback实现添加到仅忽略(或记录)错误的重试模板。

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.如果您在 Spring AMQP 之上使用Spring 集成层,则可以向出站通道适配器添加断路器请求处理程序建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM