Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy messages to another queue on RabbitMQ?

Using RabbitMQ as broker, I would like to copy all the messages from one queue to another queue for test/debug purpose. What's the simplest way via RabbitMQ web management console / cli?

P.S. Under web console for specified queue, I could only Move messages instead of Copy messages to new queue.

like image 333
northtree Avatar asked Jul 31 '18 07:07

northtree


1 Answers

When I need to perform such tasks, I do as follows (assuming you want to copy all of the messages from your reference queue):

  1. create a fanout exchange or use the default one (amq.fanout) if he isn't bound to any queue
  2. bind the reference queue to it
  3. bind the "duplicate" queue to it
  4. configure a shovel to send all the messages in the reference queue to the exchange you bound to both queues, with auto-delete set to "After initial length transferred"

But it does mean that if messages arrived to the reference queue through it's normal flow, they will end up at the top of the queue, with the "copied" messages behind/mixed with them

like image 148
Olivier Avatar answered Sep 24 '22 03:09

Olivier