Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
586 views
in Technique[技术] by (71.8m points)

python - Is it possible to move / merge messages between RabbitMQ queues?

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:

Ideally:

main-queue : ['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', dog-3, dog-4]

But this is ok too:

main-queue : ['cat-1','cat-2','cat-3','cat-4','dog-1','dog-2','cat-5', 'dog-1, dog-2, dog-3, dog-4]

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...