RabbitMQ - Export / Import Configuration
If you are deploying a fresh RabbitMQ instance, you may wish to have an easy way to export the configuration from the old instance and import into the new instance. Luckily RabbitMQ has an API, so this can be done fairly easily with the commands outlined below:
Export
Update the variables as appropriate before then running the curl command:
USERNAME="admin"
PASSWORD="myPasswordHere"
URL=http://rabbitmq.mydomain.com/api/definitions
curl --silent -u $USERNAME:$PASSWORD $URL -o config.json
Import
Update the variables as appropriate before then running the curl command:
USERNAME="admin"
PASSWORD="myPasswordHere"
URL=http://rabbitmq.mydomain.com/api/definitions
curl \
-H 'Content-Type: application/json' \
-X POST \
-u $USERNAME:$PASSWORD \
-d "@config.json" \
$URL
Hostname And Data Persistence
When using the steps above to configure a new host, I realized that the queues and exchanges were not being kept after killing and re-spawning the containers with docker compose. It turns out that I hadn't been setting the hostname of the container, and that setting the new server to have a hostname matching that of the server I was importing the configuration from resolved the issue. This is because Rabbitmq uses the hostname as part of the folder name in the mnesia directory as mentioned on this Github issue.
First published: 7th May 2024