使 Spring RabbitMQ 在缺少交换时失败 [英] Make Spring RabbitMQ fail on missing exchange

查看:20
本文介绍了使 Spring RabbitMQ 在缺少交换时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很好的属性 spring.rabbitmq.listener.simple.missing-queues-fatal=true当我将它设置为不存在的队列时,它会使 SimpleMessageListenerContainer 和整个应用程序失败 - 这就是我想要的.我不想让应用程序在无效状态下运行.

There is nice property spring.rabbitmq.listener.simple.missing-queues-fatal=true it makes SimpleMessageListenerContainer and whole application fail when I set it a non existent queue - which is what I want. I don't want to have an application running in invalid state.

我找不到类似的交流解决方案,如

I can't find similar solution for exchanges like

spring.rabbitmq.listener.simple.missing-exchanges-fatal

spring.rabbitmq.listener.simple.missing-exchanges-fatal

我进入了几个日志

ERROR 432430 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory       : Shutdown Signal: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=NOT_FOUND - no exchange 'some-non-existent-exchange' in vhost '/', class-id=40, method-id=30)

然后应用程序启动.我希望它失败.我该怎么做?

and application starts. I would like it to fail. How can I do it?

尝试绑定到任何不存在的队列或交换时,如何使 spring boot/rabbit 失败?

How can I make spring boot/rabbit fail when trying to bind to any of non existing queue or exchange?

推荐答案

交换与监听器无关.当我们将数据生成到 AMQP 中时,我们需要它和路由键.侦听器可以选择失败,因为它不受最终用户控制,并在应用程序准备好时自动启动.发送数据时,RabbitTemplate 中使用了交换.请参阅 CachingConnectionFactory 上的 publisherReturns 选项,了解像您这样的用例,以在错过交换的情况下处理此类错误:

The exchange does nothing with listener. We need it along side with a routing key when we produce data into AMQP. The listener has that option to fail because it is out of end-user control and starts automatically when application is ready. The exchange is used in the RabbitTemplate when you send a data. See publisherReturns option on the CachingConnectionFactory for use-case like yours to handle such an error in case of missed exchange:

https://docs.spring.io/spring-amqp/docs/current/reference/html/#cf-pub-conf-rethttps://www.rabbitmq.com/confirms.html

您还可以将 ReturnsCallback 添加到您的 RabbitTemplate 以捕获未路由的消息及其原因并分别处理此类错误:在您的情况下停止应用程序,例如System.exit(1);.

You also add a ReturnsCallback into your RabbitTemplate to catch an unrouted message and its reason and handle such an error respectively: in your case stop the app, e.g. System.exit(1);.

这篇关于使 Spring RabbitMQ 在缺少交换时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆