I'm looking to know is it possible to move / merge messages from one queue to another. For example:
main-queue
contains messages ['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5']
dog-queue
contains messages ['dog-1, dog-2, dog-3, dog-4]
So the question is, (assuming both queues are on the same cluster, vhost) it possible to move messages from dog-queue
to main-queue
using rabbitmqctl
?
So at the end I'm looking to get something like:
main-queue
: ['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', dog-3, dog-4]
main-queue
: ['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', 'dog-1, dog-2, dog-3, dog-4]
In order to avoid losing messages on the RabbitMQ (as opposed to application) side, queues and messages must be able to cope with RabbitMQ node restarts, node and hardware failures. With some messaging protocols supported by RabbitMQ, applications control durability of queues and messages.
Use multiple queues and consumers Queues are single-threaded in RabbitMQ, and one queue can handle up to about 50 thousand messages. You will achieve better throughput on a multi-core system if you have multiple queues and consumers and if you have as many queues as cores on the underlying node(s).
Queues in RabbitMQ are FIFO ("first in, first out").
What you are/were looking for is the 'shovel' plugin. The shovel plugin comes built into the core but you have to explicitly enable it. It's really easy to use as it does everything for you (no manually consuming/republishing to another queue).
Enable shovel plugin via cli:
sudo rabbitmq-plugins enable rabbitmq_shovel
If you manage RabbitMQ via GUI, install the shovel mgmt plugin too:
sudo rabbitmq-plugins enable rabbitmq_shovel_management
Login to the GUI and you will see Shovel Management under the Admin section. You can create shovels to move messages from any queue to another queue, even remotely hosted queues. You can delete the shovel when it's finished, or leave it there and it'll continually move the messages as they come in.
If you manage RabbitMQ via CLI, you can execute shovel directly from rabbitmqctl:
sudo rabbitmqctl set_parameter shovel cats-and-dogs \
'{"src-uri": "amqp://user:pass@host/vhost", "src-queue": "dog-queue", \
"dest-uri": "amqp://user:pass@host/vhost", "dest-queue": "main-queue"}'
Official plugin docs:
Shovel Plugin - https://www.rabbitmq.com/shovel.html
Creating Shovels - https://www.rabbitmq.com/shovel-dynamic.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With