Defining rabbitmq policies in a configuration file

I would like to define mirroring for all my default queues. Currently, I have to use rabbitmqctl after node completion:

 rabbitmqctl set_policy ha-all "" '{"ha-mode":"all"}' 

If one of my nodes fails, I will have to remember to re-execute this code on reboot.

Is there a way to automatically configure my node to use mirror queues?

+7
rabbitmq rabbitmqctl
source share
3 answers

The CAN policy can be specified in the definition file, which can be specified from your configuration file.

An example of how I set a specific policy (not sure if ha can be specified in the policy):

/etc/rabbitmq/rabbitmq.config

 [ {rabbit, [{vm_memory_high_watermark, 0.8}] }, {rabbitmq_management, [{listener, [{port, 15672}]}, {load_definitions, "/etc/rabbitmq/rabbitmq_definitions.json"}, {http_log_dir, "/var/log/rabbitmq/management_http.log"}] } ]. 

/etc/rabbitmq/rabbitmq_definitions.json

 { "users":[ {"name":"rabbot","password_hash":"Cvse5iGOg20UqUq7Za9D1tatOJnMVDru4GHtxqc02g7zj5ur","tags":""}, {"name":"rabnet","password_hash":"CqqG2fwvH6xz64NpibGJx2M7ZCyFnR1BQBM+C0KH2qRPmVxF","tags":"administrator"}], "vhosts":[ {"name":"/"}], "permissions":[ {"user":"viabot","vhost":"VIA","configure":".*","write":".*","read":".*"}, {"user":"vianet","vhost":"VIA","configure":".*","write":".*","read":".*"}], "parameters":[], "policies":[ {"vhost":"VIA","name":"DLX","pattern":".*","apply-to":"queues","definition":{"dead-letter-exchange":"dead_letter"},"priority":0} ], "queues":[ {"name":"store_to_es","vhost":"VIA","durable":true,"auto_delete":false,"arguments":{}}, {"name":"store_to_mongodb","vhost":"VIA","durable":true,"auto_delete":false,"arguments":{}} ], "exchanges":[ {"name":"data_incoming","vhost":"VIA","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}}, {"name":"sms_incoming","vhost":"VIA","type":"fanout","durable":true,"auto_delete":false,"internal":false,"arguments":{}} ], "bindings":[ {"source":"data_incoming","vhost":"VIA","destination":"store_to_es","destination_type":"queue","routing_key":"","arguments":{}}, {"source":"sms_incoming","vhost":"VIA","destination":"store_to_mongodb","destination_type":"queue","routing_key":"","arguments":{}} ] } 

I use this file for configuration files and descriptions, as it was impossible to understand on the RabbitMQ website.

Note. This configuration worked on RabbitMQ 3.6.1, running on Ubuntu 14.04

+7
source share

The policy cannot be set in the rabbitmq.config file. One way is to run rmq using the init script and put the rabbitmqctl command in it so that it starts whenever rmq starts or restarts.

+1
source share

I searched the same thing and found this question. To add more details to IvanD's answer, this is how I did it:

First: sudo nano /etc/rabbitmq/rabbitmq.config (this command may vary depending on your OS)

 [ {rabbit, [ {default_vhost,<<"/">>}, {default_user,<<"someuser">>}, {default_pass,<<"somepassword">>}, {default_permissions, [<<".*">>, <<".*">>, <<".*">>]}, {default_user_tags, [administrator]} ] }, {rabbitmq_management, [{listener, [{port, 15672}]}, {load_definitions, "/etc/rabbitmq/rabbitmq_definitions.json"}, {http_log_dir, "/var/log/rabbitmq/management_http.log"}] } ]. 

Then create additional json: sudo nano /etc/rabbitmq/rabbitmq_definitions.json (this command may differ depending on your OS) And this content:

 { "vhosts":[ {"name":"/"} ], "policies":[ {"vhost":"/","name":"ha","pattern":"", "definition":{"ha-mode":"all","ha-sync-mode":"automatic","ha-sync-batch-size":5}} ] } 

IMPORTANT NOTE! Ga-sync-batch size is only supported on rabbitmq versions above 3.6.0! https://www.rabbitmq.com/ha.html#sync-batch-size If your rabbit is older than this, remove the setting from rabbitmq_definitions.json .

I am using ubuntu 14.04 Trusty and Rabbitmq v.3.6.2.

0
source share

All Articles