Define RabbitMQ policies in configuration file

前端 未结 5 1000
清歌不尽
清歌不尽 2021-02-02 12:50

I\'d like to define mirroring for all my queues by default. I currently have to use rabbitmqctl once the node is up:

rabbit         


        
5条回答
  •  粉色の甜心
    2021-02-02 13:46

    Yes, You can load policies, queues, exchanges, bindings, users and much more directly on restart using definition import at load time.

    1. Preconfigure you Rabbit

      Go to http://localhost:15672 Admin -> Policies page and create a new policy you need:

      You may also preconfigure queues and other things.

    2. Dump definitions

      curl -s -H "Accept:application/json" -u guest:guest http://localhost:15672/api/definitions > definitions.json

      You can also dump your definitions using web interface. Open Overview tab, scroll down:

      (!!!) Alter definitions.json, so as to keep things you need on restart only.

      There will be section withing your policies, keep it:

      ...
      "policies": [
        {
          "vhost": "/",
          "name": "ha-all",
          "pattern": "",
          "apply-to": "all",
          "definition": {
            "ha-mode": "all"
          },
          "priority": 0
        }
      ]
      ...
      
    3. Load definitions on restart

      Put that definitions.json nearby your rabbit and add this line to rabbit.conf. No need to use old format:

      management.load_definitions = /path/to/definitions.json
      

    So as to load something after restart use cli tools.


    Paying tribute to @IvanD since my answer is pretty much the same as his own but reveals detailed steps and new config format usage. Not enough space in comment.

提交回复
热议问题