Skip to content

Instantly share code, notes, and snippets.

@Horb
Created August 16, 2020 23:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Horb/e87125d30df16360f9f768369b576cd7 to your computer and use it in GitHub Desktop.
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.
#!/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