What is Queue Mirroring
By default, contents of a queue within a RabbitMQ cluster are located on a single node (the node on which the queue was declared). This is in contrast to exchanges and bindings, which can always be considered to be on all nodes. Queues can optionally be made mirrored across multiple nodes. Each mirrored queue consists of one master and one or more mirrors, with the oldest mirror being promoted to the new master if the old master disappears for any reason.
默认情况下,RabbitMQ集群中的队列的内容位于单个节点(宣布队列的节点)上。这与交换和绑定形成了鲜明的对比,而交换和绑定总是可以被认为是在所有节点上。队列可以选择性地跨多个节点进行镜像。每个镜像队列由一个主和一个或多个镜像组成,如果老的主因任何原因消失,则将最旧的镜像提升为新主人。
镜像到底是什么
There are multiple terms commonly used to identify primary and secondary replicas in a distributed system. This guide typically uses "master" to refer to the primary replica of a queue and "mirror" for secondary replicas. However, you will find "slave" used here and there. This is because RabbitMQ CLI tools historically have been using the term "slave" to refer to secondaries. Therefore both terms are currently used interchangeably but we'd like to eventually get rid of the legacy terminology.
在分布式系统中,通常使用多个术语来标识主要副本和辅助副本。本指南通常使用“主”来指代队列的主要副本,而对于辅助副本则使用“镜像”。然而,你会发现“奴隶”在这里和那里使用。这是因为RabbitMQ CLI工具历史上一直使用术语“奴隶”来指代辅助。因此,这两个术语目前可以互换使用,但我们希望最终摆脱传统术语。
How Mirroring is Configured
Mirroring parameters are configured using policies. A policy matches one or more queues by name (using a regular expression pattern) and contains a definition (a map of optional arguments) that are added to the total set of properties of the matching queues. Please see Runtime Parameters and Policies for more information on policies.
镜像参数是使用策略配置的。策略通过名称(使用正则表达式模式)匹配一个或多个队列,并包含添加到匹配队列的全部属性集中的定义(可选参数的映射)。有关策略 的更多信息,请参阅运行时参数和策略。
可以通过WEB-UI的方式来配置镜像队列例子
步骤详解:
Name: policy的名称 名称随意起
Pattern: queue的匹配模式(正则表达式) 这里填 ^ 代表匹配所有
Definition:
第一行点击下方的ha-mode 在后面填入all(镜像队列将会在整个集群中复制。当一个新的节点加入后,也会在这 个节点上复制一份。)
第二行点击ha-sync-mode 在后面填入automatic
最后点击Add proclicy
配置详解
HA-MODE | HA-PARAMS | 功能 |
---|---|---|
all | 空 | 镜像队列将会在整个集群中复制。当一个新的节点加入后,也会在这 个节点上复制一份。 该设置非常保守,建议改为使用集群节点的quorum(n/2+1)。对所有节点进行镜像会对所有集群节点造成额外的压力,包括网络输入/输出、磁盘输入输出和磁盘空间使用。主要是集群节点之间的同步。 |
exactly | count | 镜像队列将会在集群上复制count份。如果集群数量少于count时候,队列会复制到所有节点上。如果大于Count集群,有一个节点crash后,新进入节点也不会做新的镜像。 |
nodes | node name | 镜像队列会在node name中复制。如果这个名称不是集群中的一个,这不会触发错误。如果在这个node list中没有一个节点在线,那么这个queue会被声明在client连接的节点。 |
也可以通过命令的方式配置镜像队列
rabbitmqctl set_policy -p 'ecas' --priority 9 --apply-to all ecas-ha "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}' 给vhost为ecas 的所有的队列配置镜像队列
其他配置请参考