构建RabbitMQ集群架构
RabbitMQ集群架构模式有多种,本章将对这些模式进行讲解,并对一些重点的模式进行手把手搭建教学。先来一下RabbitMQ中的集中集群模式:
1.主备模式
实现RabbitMQ的高可用集群,一般在并发和数据量不高的情况下,这种模型非常的好用且简单。主备模式也称之为Warren模式。主节点如果挂了,从节点提供服务而已,和activemq利用zk做主/备一样。这里要特别注意,主备模式不是主从模式,主备模式从节点不提供读,主从模式,从节点会为主节点分担读的压力。


2.远程模式
实现双活的一种模式,简称Shovel模式,所谓shovel就是我们可以把消息进行不同数据中心的复制工作,我们可以跨地域的让两个mq集群互联。





3.镜像模式(重点)
集群模式非常经典的就是Mirror镜像模式,保证100%数据不丢失,在实际工作中也是用的最多的。并且实现集群非常的简单,一般互联网大厂都会构建这种镜像集群模式。
Mirror镜像队列,目的就是为了保证rabbitMq数据的高可靠性解决方案,主要就是实现数据的同步,一般来讲是2-3个节点实现数据同步(对于100%数据可靠性解决方案一般是3节点)集群架构如下:

我们使用了HA-proxy做负载均衡,为了保证1个HA-proxy在挂掉的情况下,集群保持正常使用,所以使用keepAlived做IP漂移。
4.多活模式
这种模式也是实现异地数据复制的主流模式,因为Shovel模式配置比较复杂,所以一般来说实现异地集群都是使用这种双活或者多活模型来实现的。这种模型需要依赖rabbitmq的federation插件,可以实现持续的可靠的AMQP数据通信,多活模式在实际配置与应用非常的简单。
RabbitMQ部署架构采用双中心模式(多中心),那么在两套(或多套)数据中心各部署一套RabbitMQ集群,各中心的RabbitMQ服务除了需要为业务提供正常的消息服务外,中心之间还需要实现部分队列消息共享。多活集群架构如下:






















