How to copy messages to another queue on RabbitMQ?
Asked Answered
K

5

10

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.

Koppel answered 31/7, 2018 at 7:6 Comment(0)
M
11

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

Main answered 2/8, 2018 at 13:12 Comment(1)
I've created a bash script here that implements this method using the Management HTTP API.Schooner
E
4

Go to http://localhost:15672/#/queues

  1. Create vhost (vhost=testhost)
  2. Create two queue using vhost( Test1, Test2)
  3. Create exchange Test_exchange: http://localhost:15672/#/exchanges
  4. Bind these queue(Test1 & Test2) on Test_exchange
  5. Install shovel
  6. sudo rabbitmq-plugins enable rabbitmq_shovel
  7. sudo rabbitmq-plugins enable rabbitmq_shovel_management
  8. Add shovel using admin shovel tab
    • URI: amqp://{user}:{pass}@{localhost}:5672/vhost (this is for reference queue which u want to create copy, vhost if it has) source

Destination URI: amqp://user:pass@localhost:5672/Test_exchnage

Queue Name: “Test_exchange”

You can can send msg to your reference queue.

Edacity answered 23/4, 2020 at 9:18 Comment(0)
T
3

just create another queue with the same routing key if the exchange is a direct exchange

Traynor answered 2/9, 2020 at 15:13 Comment(0)
L
0

With direct exchange, I found the simplest way is to:

  • create new exchange X manually.
  • create new queue X manually
  • bind new exchange to new queue.
  • bind old exchange to X queue.
Leadbelly answered 26/7, 2024 at 10:24 Comment(0)
B
-2

There's a commercial tool, QueueExplorer (disclaimer - I'm the author) which allows you to copy messages, among other things.

Bull answered 1/8, 2018 at 19:1 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.