Search code examples
rabbitmqspring-rabbit

How can I trigger message duplication in RabbitMQ for testing?


The RabbitMQ documentation says, that duplication of messages could happen, and the consumer must handle this. In order to test the appropriate code, I'd like to make RabbitMQ produce these duplicate messages, with the redelivered flag set accordingly. How can I do this?


Solution

  • With default configuration, if you throw an exception from the listener, it will be redelivered - if you have multiple consumers on the queue, there is no guarantee the same instance will get the redelivery.