Use RabbitMQ Management API to export or import configuration.
RabbitMQ version.
$ sudo rabbitmq-diagnostics server_version Asking node rabbit@buster for its RabbitMQ version... 3.7.18
RabbitMQ Management API
Export
Download, pretty-print and store configuration using RabbitMQ Management API.
$ curl --silent --user admin:password --header "Content-type: application/json" http://127.0.0.1:15672/api/definitions | jq . | tee config.json { "rabbit_version": "3.7.18", "users": [ { "name": "admin", "password_hash": "o3i3s4OowPHuaODMFwe3bE/GORgEDI7MrTnRCNX9SRZR0CnS", "hashing_algorithm": "rabbit_password_hashing_sha256", "tags": "administrator" } ], "vhosts": [ { "name": "/" } ], "permissions": [ { "user": "admin", "vhost": "/", "configure": ".*", "write": ".*", "read": ".*" } ], "topic_permissions": [], "parameters": [], "global_parameters": [ { "name": "cluster_name", "value": "rabbit@buster.localdomain" } ], "policies": [], "queues": [], "exchanges": [], "bindings": [] }
Import
Imported configuration will be merged. This is important to know. Reset RabbitMQ configuration if you need to.
Create partial configuration.
$ cat << EOF | tee monitoring_user_config.json { "users": [ { "name": "monitoring", "password": "monitoring", "tags": "monitoring" } ], "permissions": [ { "user": "monitoring", "vhost": "/", "configure": "", "write": "", "read": "" } ], } EOF
Import the above-mentioned configuration.
$ curl --user admin:password --data "@monitoring_user_config.json" --header "Content-Type: application/json" --request POST http://127.0.0.1:15672/api/definitions
Verify RabbitMQ configuration.
$ curl -s -u admin:password -H "Content-type: application/json" http://127.0.0.1:15672/api/definitions | jq . { "rabbit_version": "3.7.18", "users": [ { "name": "admin", "password_hash": "o3i3s4OowPHuaODMFwe3bE/GORgEDI7MrTnRCNX9SRZR0CnS", "hashing_algorithm": "rabbit_password_hashing_sha256", "tags": "administrator" }, { "name": "monitoring", "password_hash": "HI8MXbxtqLOREKdDtkeuO7kA8bPWVnOF+YMhvmSRMSK3ixNI", "hashing_algorithm": "rabbit_password_hashing_sha256", "tags": "monitoring" } ], "vhosts": [ { "name": "/" } ], "permissions": [ { "user": "monitoring", "vhost": "/", "configure": "", "write": "", "read": "" }, { "user": "admin", "vhost": "/", "configure": ".*", "write": ".*", "read": ".*" } ], "topic_permissions": [], "parameters": [], "global_parameters": [ { "name": "cluster_name", "value": "rabbit@buster.localdomain" } ], "policies": [], "queues": [], "exchanges": [], "bindings": [] }
RabbitMQ admin utility
This is a simpler solution using Python, but inner API calls are the same.
Notice that RabbitMQ Management plugin needs to be enabled.
Download rabbitmqadmin
utility.
$ curl -o rabbitmqadmin http://127.0.0.1:15672/cli/rabbitmqadmin
Ensure that executable bit is set.
$ chmod +x rabbitmqadmin
Inspect application parameters.
$ ./rabbitmqadmin --help Usage ===== rabbitmqadmin [options] subcommand Options ======= --help, -h show this help message and exit --config=CONFIG, -c CONFIG configuration file [default: ~/.rabbitmqadmin.conf] --node=NODE, -N NODE node described in the configuration file [default: 'default' only if configuration file is specified] --host=HOST, -H HOST connect to host HOST [default: localhost] --port=PORT, -P PORT connect to port PORT [default: 15672] --path-prefix=PATH_PREFIX use specific URI path prefix for the RabbitMQ HTTP API. /api and operation path will be appended to it. (default: blank string) [default: ] --vhost=VHOST, -V VHOST connect to vhost VHOST [default: all vhosts for list, '/' for declare] --username=USERNAME, -u USERNAME connect using username USERNAME [default: guest] --password=PASSWORD, -p PASSWORD connect using password PASSWORD [default: guest] --base-uri=URI, -U URI connect using a base HTTP API URI. /api and operation path will be appended to it. Path will be ignored. --vhost has to be provided separately. --quiet, -q suppress status messages [default: True] --ssl, -s connect with ssl [default: False] --ssl-key-file=SSL_KEY_FILE PEM format key file for SSL --ssl-cert-file=SSL_CERT_FILE PEM format certificate file for SSL --ssl-ca-cert-file=SSL_CA_CERT_FILE PEM format CA certificate file for SSL --ssl-disable-hostname-verification Disables peer hostname verification --ssl-insecure, -k Disables all SSL validations like curl's '-k' argument --request-timeout=REQUEST_TIMEOUT, -t REQUEST_TIMEOUT HTTP request timeout in seconds [default: 120] --format=FORMAT, -f FORMAT format for listing commands - one of [raw_json, long, pretty_json, kvp, tsv, table, bash] [default: table] --sort=SORT, -S SORT sort key for listing queries --sort-reverse, -R reverse the sort order --depth=DEPTH, -d DEPTH maximum depth to recurse for listing tables [default: 1] --bash-completion Print bash completion script [default: False] --version Display version and exit More Help ========= For more help use the help subcommand: rabbitmqadmin help subcommands # For a list of available subcommands rabbitmqadmin help config # For help with the configuration file
Export
Export configuration.
$ ./rabbitmqadmin --username admin --password password export config.json Exported definitions for localhost to "config.json"
Import
Import configuration.
$ ./rabbitmqadmin --username admin --password password import config.json Uploaded definitions from "localhost" to config.json. The import process may take some time. Consult server logs to track progress.