
A shovel is used to move a message from a queue or exchange to a different queue or exchage. The queues or exchanges can reside on the same RabbitMQ node or on different RabbitMQ nodes.
AVOID TROUBLE
There are two types of shovels.
- Dynamic - Created using the rabbitmqctl set_parameter command, or using the RabbitMQ REST API, or using the RabbitMQ web browser console, or using Terraform (this article)
- Static - defined in advanced.config, node must be restarted to create/delete a static shovel
Only a dynamic shovel can be deleted using the rabbitmqctl clear_parameter command.
The src-delete-after parameter can be used to delete a dynamic shovel when:
- The queue-length of the source queue will be measure, which is the count of messages in the queue, and the shovel will be deleted after the queue length has been reached.
- The shovel will be deleted after "x" messages have been moved, where "x" is an integer value.
The src-delete-after parameter defaults to never, meaning that a shovel will not be automatically deleted.
queue-length
Let's say you use the rabbitmqctl set_parameter command to create a shovel named shove001 in the foo virtual host, to move messages from a.queue to b.queue. In this example, queue-length is used.
If there are 10 messages in a.queue, then the shovel will be deleted once all 10 messages have been moved to b.queue.
rabbitmqctl set_parameter shovel shovel001
'{
"src-uri": "amqp:///foo",
"src-queue": "a.queue",
"src-delete-after": "queue-length",
"dest-uri": "amqp:///foo",
"dest-queue": "b.queue"
}'
--vhost foo
custom integer
Let's say you use the rabbitmqctl set_parameter command to create a shovel named shove001 in the foo virtual host, to move messages from a.queue to b.queue. In this example, src-delete-after: 1 is used, meaning that the shovel will be deleted after 1 messages is moved from a.queue to b.queue.
rabbitmqctl set_parameter shovel shovel001
'{
"src-uri": "amqp:///foo",
"src-queue": "a.queue",
"src-delete-after": 1,
"src-prefetch-count": 1,
"dest-uri": "amqp:///foo",
"dest-queue": "b.queue"
}'
--vhost foo
Did you find this article helpful?
If so, consider buying me a coffee over at