java - Spring AMQP : [RabbitTemplate] Hystrix fallback is not getting invoked when RabbitTemplate ReturnCallback is executed

标签 java spring spring-amqp hystrix

当我的消息未传递到 RabbitMQ 服务器时,我使用 hystrix 来处理回退场景。当 RabbitMQ 服务器关闭时(抛出 AMQPException ),我的后备将被调用。 如果代理无法接受/路由消息,则调用 returnCallback/returnConfirm(with nack)。
我的理解是 RabbitTemplate returnCallbacks/returnConfirms 将在与 Hystrix 线程不同的线程中执行。

在这些场景中是否可以抛出异常以便执行 Hystrix 回退?

我提到了这些问题:Spring AMQP return callback vs retry callback

Spring RabbitTemplate- How to get hold of the published message for NACKs in Publisher confirm mode

非常感谢任何处理这种情况的指针。

最佳答案

没有;返回完全异步;即使您启用交易 - 来自the rabbit mq documentation ...

AMQP does not specify when errors (e.g. lack of permissions, references to unknown exchanges) in transactional basic.publish and basic.ack commands should be detected. RabbitMQ performs the necessary checks immediately (rather than, say, at the time of commit), but note that both basic.publish and basic.ack are asynchronous commands so any errors will be reported back to the client asynchronously.

如果您发布到不存在的交换器(以及setChannelTransacted(true)*),您将在提交时遇到异常,但发布到没有可路由队列的交换器永远不会遇到异常(仅异步返回回调)。

  • 启用事务对于所有操作来说都相当昂贵,因此如果您想捕捉这种特定场景,请仔细考虑

关于java - Spring AMQP : [RabbitTemplate] Hystrix fallback is not getting invoked when RabbitTemplate ReturnCallback is executed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39480898/

相关文章:

java - 大型数据库不应该使用hibernate吗

java - 如何在同一个 ehCache 中缓存 2 个不同的 bean 方法?

java - 带有事务管理器和重试建议顺序的 Spring 监听器容器

java - 最新的spring-rabbit不支持encoder标签?

java - 无法为 Pulsar 设置 Zookeeper 集群

java - 使用 SimpleDateFormat 时出错

java - 尝试某些请求时出现 Spring Security 和 Angular 401 错误

rabbitmq - Spring-rabbit - ReturnCallback 未触发

java - 自动装箱原始文字是否有性能成本?

java - 自定义soapfault解析器触发但未在SoapBody中找到SoapFault