A simple Node.js script to move messages between AMQP queues using the RabbitMQ Management API.
This script allows you to move messages from one queue to another in a RabbitMQ instance. It fetches messages from the origin queue and publishes them to the destination queue using the RabbitMQ HTTP API.
- Node.js (version 14 or higher)
- Access to RabbitMQ Management API
- Valid authentication token for the RabbitMQ instance
AMQP_TOKEN- Base64 encoded authentication token for RabbitMQ Management API
npx https://gist.github.com/filiafobico/ecc52e8bb539c8a9302fb4c67b6b3863 \
--host=https://your-rabbitmq-host.com \
--origin=source-queue-name \
--destination=target-queue-name \
--vhost=your-virtual-host \
--count=10# Set your authentication token
export AMQP_TOKEN="your_base64_encoded_token"
# Run the script
node index.mjs \
--host=https://your-rabbitmq-host.com \
--origin=source-queue-name \
--destination=target-queue-name \
--vhost=your-virtual-host \
--count=10| Parameter | Required | Description | Default |
|---|---|---|---|
--host |
Yes | RabbitMQ Management API base URL | - |
--origin |
Yes | Source queue name | - |
--destination |
Yes | Destination queue name | - |
--vhost |
Yes | Virtual host name | - |
--count |
No | Number of messages to move | 1 |
The AMQP_TOKEN should be a Base64 encoded string of your RabbitMQ username and password:
echo -n "username:password" | base64# Set token
export AMQP_TOKEN="dXNlcm5hbWU6cGFzc3dvcmQ="
# Move 5 messages from dlq to main queue
npx https://gist.github.com/filiafobico/ecc52e8bb539c8a9302fb4c67b6b3863 \
--host=https://rabbitmq.example.com \
--origin=my-service.dlq \
--destination=my-service.main \
--vhost=production \
--count=5- Messages are acknowledged and removed from the source queue after being moved
- The script preserves message properties during the move operation
- All messages are logged to the console during processing
- If any required parameter is missing, the script will exit with an error message
The script includes basic error handling and will:
- Validate all required parameters before execution
- Log errors for failed API calls
- Exit with code 1 if required parameters are missing