1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| 1、首先查看策略
#rabbitmqctl -n rabbit1 list_policies #以节点rabbit2和rabbit3查询结果是一样的
Listing policies
2、设置镜像队列策略
用法:
set_policy [-p vhost] [--priority priority] [--apply-to apply-to] {name} {pattern} {definition}
Sets a policy.
name
The name of the policy.
pattern
The regular expression, which when matches on a given resources causes the policy to apply.
definition
The definition of the policy, as a JSON term. In most shells you are very likely to need to quote this.
priority
The priority of the policy as an integer. Higher numbers indicate greater precedence. The default is 0.
apply-to
Which types of object this policy should apply to - "queues", "exchanges" or "all". The default is "all".
For example:
rabbitmqctl set_policy federate-me "^amq." '{"federation-upstream-set":"all"}'
This command sets the policy federate-me in the default virtual host so that built-in exchanges are federated.
释义:
-p Vhost: 可选参数,针对指定vhost下的queue进行设置
Name: policy的名称,可以自定义
Pattern: queue的匹配模式(正则表达式)
Definition: 镜像定义,包括三个部分ha-mode, ha-params, ha-sync-mode
ha-mode: 指明镜像队列的模式,有效值为 all/exactly/nodes
all: 表示在集群中所有的节点上进行镜像
exactly: 表示在指定个数的节点上进行镜像,节点的个数由ha-params指定
nodes: 表示在指定的节点上进行镜像,节点名称通过ha-params指定
ha-params: ha-mode模式需要用到的参数
ha-sync-mode: 进行队列中消息的同步方式,有效值为automatic和manual
priority: 可选参数,policy的优先级
ha-promote-on-shutdown: 用来控制选主的行为的,有效值为when-synced,always
3、开始设置:
#rabbitmqctl -n rabbit1 set_policy mirror_queue "^" '{"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"}'
Setting policy "mirror_queue" for pattern "^" to "{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\",\"ha-promote-on-shutdown\":\"always\"}" with priority "0"
4、再次查看策略
#rabbitmqctl -n rabbit1 list_policies
Listing policies
/ mirror_queue all ^ {"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"} 0
#rabbitmqctl -n rabbit2 list_policies
Listing policies
/ mirror_queue all ^ {"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"} 0
#rabbitmqctl -n rabbit3 list_policies
Listing policies
/ mirror_queue all ^ {"ha-mode":"all","ha-sync-mode":"automatic","ha-promote-on-shutdown":"always"} 0
|