Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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). 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. 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. But really, any way to cause a NACK during a test would be great.

tl;dr how to nack a message from client code

like image 758
John Sandfort Avatar asked Feb 08 '16 20:02

John Sandfort


People also ask

What happens if message not acknowledged RabbitMQ?

RabbitMQ Unacked Messages are the messages that are not Acknowledged. If a consumer fails to acknowledge messages, the RabbitMQ will keep sending new messages until the prefetch value set for the associated channel is equal to the number of RabbitMQ Unacked Messages count.

What does Nack do RabbitMQ?

nack was introduced by RabbitMQ as a protocol extension. When the multiple field is set to true , RabbitMQ will acknowledge all outstanding delivery tags up to and including the tag specified in the acknowledgement. Like everything else related to acknowledgements, this is scoped per channel.

What happens when RabbitMQ is down?

In detail: The messages that RabbitMQ publish are persistent. When the message broker goes down, the events are not published and I am planning to store these events in a database and publish them again to RabbitMQ when it is up.

What is Nack queue?

nack complements the bulk acknowledgement semantics of basic. ack. Negative acknowledgements work for both long running consumers and polling-based ones (that use basic. get). When a message is requeued, it will be placed to its original position in its queue, if possible.


1 Answers

Publishing a message to a nonexistent exchange will cause the publisher confirm callback to receive a nack!

like image 54
John Sandfort Avatar answered Sep 27 '22 21:09

John Sandfort