Loading

# 镜像集群模式

镜像集群模式

概览

一共3台的集群。

22,23,24.

开启镜像队列功能之前

22上新建了一个队列,按理说,数据都会在22的队列上存放。

我这里建了个队列,名为test-queue

这里的rabbitmq01,就是此处的22服务器。这里也说明了,test-queue归属于22这个服务器node。

我们在22上发布了一条消息:

接下来,我们到23上去get这条message。在此之前,先在23服务器上,执行以下命令:

tcpdump -i ens192 host 10.15.10.22 and tcp port 25672 -Ann -w 23.pcap

这条命令,捕获本服务器(23)上和22的25672之间的通信。

然后,去23上get这条message。

这里get后,完成服务器上的tcpdump抓包,将23.pcap拿到windows上,用wireshark分析。

很容易看出,实际上,是22将消息内容返回给23的。

开启之后

开启了这个之后,看看现在是什么情况呢?

现在,相当于,22和24上有了这个队列的内容,但是23上没有。

之前把ha-policy设为exactly,ha-params设为2,这个2,看来是包含了其master的。

我找到了官网注释,如下:

https://www.rabbitmq.com/ha.html

Number of queue replicas (master plus mirrors) in the cluster. A count value of 1 means a single replica: just the queue master. If the node running the queue master becomes unavailable, the behaviour depends on queue durability. A count value of 2 means 2 replicas: 1 queue master and 1 queue mirror. In other words: NumberOfQueueMirrors = NumberOfNodes - 1. If the node running the queue master becomes unavailable, the queue mirror will be automatically promoted to master according to the mirror promotion strategy configured. If there are fewer than count nodes in the cluster, the queue is mirrored to all nodes. If there are more than count nodes in the cluster, and a node containing a mirror goes down, then a new mirror will be created on another node. Use of exactly mode with "ha-promote-on-shutdown": "always" can be dangerous since queues can migrate across a cluster and become unsynced as it is brought down.

之前为啥把这个设为2呢,因为官网也有推荐:

Mirroring to all nodes is the most conservative option. It will put additional strain on all cluster nodes, including network I/O, disk I/O and disk space usage. Having a replica on every node is unnecessary in most cases.

For clusters of 3 and more nodes it is recommended to replicate to a quorum (the majority) of nodes, e.g. 2 nodes in a 3 node cluster or 3 nodes in a 5 node cluster.

在23上去getMessage

发现是去22取的,没毛病。

在24上去getMessage

24上,自己是mirror了该队列的,那么,会去22取,还是就在自己本地取呢?

结果还是去22上获取的,真是奇怪。

关闭22节点

22节点,是我们那个队列的主节点。现在关闭后,会怎样呢?

在24上看看队列情况:

过了一会之后,节点状态变为:已同步。

在24和23上,去getMessage,结果发现,数据没了。

暂时不知道具体原因。可能是我getMessage的方式不对。

但是后续再测试,又是可以拿到队列数据的,奇怪。

参考:
RabbitMQ 的延时队列和镜像队列原理与实战
https://mp.weixin.qq.com/s/Ds01iOpZJEb5av3y9prSsQ

posted @ 2020-06-22 14:20  三国梦回  阅读(265)  评论(0)    收藏  举报