Created
August 16, 2020 23:23
-
-
Save Horb/e87125d30df16360f9f768369b576cd7 to your computer and use it in GitHub Desktop.
How to copy a queue in RabbitMQ using the method described here; https://stackoverflow.com/questions/51607343/how-to-copy-messages-to-another-queue-on-rabbitmq.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ADMIN_URL="$1"; | |
ORIG="$2"; | |
COPY="$3"; | |
# Create the COPY queue. | |
curl "$ADMIN_URL/api/queues/%2F/$ORIG" \ | |
| curl -X PUT "$ADMIN_URL/api/queues/%2F/$COPY" -d @-; | |
# Create the COPY exchange. | |
curl \ | |
-X PUT \ | |
-d "{ | |
\"type\": \"fanout\", | |
\"auto_delete\": true, | |
\"durable\": false, | |
\"internal\": false, | |
\"arguments\": {} | |
}" \ | |
"$ADMIN_URL/api/exchanges/%2F/$COPY"; | |
# Bind COPY exchange to ORIG and COPY queues. | |
curl -X POST -d '{}' "$ADMIN_URL/api/bindings/%2F/e/$COPY/q/$ORIG"; | |
curl -X POST -d '{}' "$ADMIN_URL/api/bindings/%2F/e/$COPY/q/$COPY"; | |
# Shovel the ORIG queue into the COPY exchange. | |
curl -X PUT "$ADMIN_URL/api/parameters/shovel/%2F/$COPY" \ | |
-d "{ | |
\"value\": { | |
\"src-protocol\": \"amqp091\", | |
\"src-uri\": \"amqp://\", | |
\"src-queue\": \"$ORIG\", | |
\"dest-protocol\": \"amqp091\", | |
\"dest-uri\": \"amqp://\", | |
\"dest-exchange\": \"$COPY\", | |
\"src-delete-after\": \"queue-length\", | |
} | |
}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment