Programster's Blog

Tutorials focusing on Linux, programming, and open-source

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:

This tutorial assumes you are using plain HTTP and that you have mapped the web management interface ports to 80/443, but you should be able to easily adjust if you are using HTTPS and/or you have not re-mapped the default ports.

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

After running the command you will just have the generated config.json file. There will be no output from having run the command.

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.

Last updated: 8th July 2024
First published: 7th May 2024