在配置文件中定义 RabbitMQ 策略 [英] Define RabbitMQ policies in configuration file

查看:33
本文介绍了在配置文件中定义 RabbitMQ 策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想默认为我的所有队列定义镜像.一旦节点启动,我目前必须 使用 rabbitmqctl :

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

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

如果我的一个节点发生故障,我必须记住在重启时重新执行该代码.

If one of my nodes fail, I'd have to remember to re-execute that code on restart.

有没有办法自动配置我的节点以使用镜像队列?

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

推荐答案

策略可以在定义文件中指定,可以从你的配置文件中引用.

Policy CAN be specified in a definition file, which can be referred to from your config file.

我如何设置特定策略的示例(不确定是否可以在策略中指定 ha):

Example of how I have set a specific policy (not sure if ha can be specified in 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":{}}
    ]
}

我正在共享此配置文件和定义文件,因为无法从 RabbitMQ 网站找出它.

I am sharing this config file and definitions file as it was impossible to figure it out from the RabbitMQ web site.

注意:此配置适用于在 Ubuntu 14.04 上运行的 RabbitMQ 3.6.1 

Note: This config worked on RabbitMQ 3.6.1 running on Ubuntu 14.04  

这篇关于在配置文件中定义 RabbitMQ 策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆