简体   繁体   English

如何强制RabbitMQ代理NACK消息进行测试?

[英]How can I force a RabbitMQ broker to NACK a message for testing?

I'm working on a Spring Boot project using RabbitMQ via Spring AMQP. 我正在通过Spring AMQP使用RabbitMQ开发Spring Boot项目。 We'd like to be able to test our app's behavior when a message publish is NACK'd (specifically when the ack argument of PublisherConfirmCallback#confirm is false ). 当消息发布为NACK时(特别是当PublisherConfirmCallback#confirmack参数为false ),我们希望能够测试应用程序的行为。 However we're having a hard time trying to set up this scenario in an integration test (that is, with the app running, not a unit test). 但是,我们很难尝试在集成测试中设置此场景(即,应用程序正在运行,而不是单元测试)。

Just to be clear, we're testing around publisher acknowledgements, not consumer acknowledgements. 为了清楚起见,我们正在测试发布者的确认,而不是消费者的认可。

We know you can get access to a channel with the RabbitTemplate's execute method, but our RabbitMQ auto-acks, so the message is already gone by the time the channel callback is executed. 我们知道您可以使用RabbitTemplate的execute方法访问通道,但是我们的RabbitMQ自动execute ,因此在执行通道回调时消息已经消失。 We're thinking we might be able to either disable auto-ack at runtime (so as not to interrupt the test suite) or to simply block the channel and receive the message on it manually in the test, but we can't figure out how to do either of these. 我们认为我们可以在运行时禁用auto-ack(以免中断测试套件)或者只是阻止通道并在测试中手动接收它,但是我们无法弄清楚怎么做其中任何一个。 But really, any way to cause a NACK during a test would be great. 但实际上,在测试过程中任何导致NACK的方法都会很棒。

tl;dr how to nack a message from client code tl; dr如何从客户端代码中取消消息

you will have to turn off auto-ack, to start with. 你将不得不关闭自动确认,开始。 with that turned on, it will not be possible to nack a message. 打开它后,就无法收到消息。

after that, you're test setup should include a message consumer that is coded specifically to do what you want, when you want... don't use your real code to test the nack handling. 在那之后,你的测试设置应该包括一个消息使用者,它被专门编写为你想要的,当你想要的时候......不要使用真实的代码来测试nack处理。 set up a consumer that only does a nack... or one that knows when it receives certain messages, it should nack 设置一个只做一个nack的消费者......或者知道什么时候收到某些消息的消费者,它应该是nack

将消息发布到不存在的交换将导致发布者确认回调以接收nack!

暂无
暂无

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

相关问题 如何在 Spring4 中将 convertAndSendToUser() 与外部代理(例如 RabbitMQ)一起使用? - How do I use convertAndSendToUser() with an external broker such as RabbitMQ in Spring4? basicAck不会从代理中删除消息 - RabbitMQ - basicAck does not remove message from broker - RabbitMQ 在当前消息之前确认所有消息,并在Ack当前消息之前确认所有消息(rabbitmq,java) - Nack all messages before current message and Ack current message (rabbitmq, java) 我可以在没有 Message Broker 的情况下使用 Spring Integration 吗 - Can I use Spring Integration without Message Broker 在集群环境中使用外部消息代理(RabbitMQ)将Spring套接字转换并发送给用户 - spring socket convertandsendtouser with external message broker(RabbitMQ) in cluster environment 如何从SWT(带有SWTBot)测试消息对话框/框? - How can I testing the Message Dialog/Box from SWT(with SWTBot)? 我如何等待,直到RabbitMQ消息已同步到集群中的其他节点? - How can i wait until a RabbitMQ message has been synced to the other nodes in the cluster? 如何在 Java Spring 中使用没有 @KafkaListener 的 KafkaTemplate 使用来自 Kafka 的消息? RabbitMQ 模拟 - How I can consume message form Kafka using KafkaTemplate without @KafkaListener in Java Spring? RabbitMQ analogue 生产者如何访问消息代理发送的确认? - How producer can access the acknowledgement sent by message broker? 如何设置spring-rabbitmq侦听器的接收速率 - How can I set the spring-rabbitmq listener's rate of receive message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM