---
title: "RabbitMq Cluster 和 High Availability"
author: "ncs123"
date: "2018-01-17T14:12:01Z"
tags: []
categories: ["编程语言"]
slug: "rabbitmq-cluster-high-availability"
draft: false
lastmod: "2018-01-25T09:59:13Z"
id: 2407942
url: "https://ncs123.iteye.com/blog/2407942"
---

[RabbitMq简介](http://ncs123.iteye.com/blog/2393969)
[RabbitMq exchange四种方式](http://ncs123.iteye.com/blog/2393995)
[RabbitMq Consumer和Producer端使用](http://ncs123.iteye.com/blog/2408255)
[RabbitMq确认机制](http://ncs123.iteye.com/blog/2394006)
<span style="color:red">RabbitMq Cluster 和 High Availability</span>

**一、RabbitMq Cluster**

![](http://dl2.iteye.com/upload/attachment/0128/5733/594af0bf-273a-371b-b011-fb51e658c270.jpeg)


所有节点两两相连
users, virtual hosts, exchanges, bindings,queue metadata会自动镜像到所有Node
连接任意一个Node都能看到集群中的所有Queue
在集群中的所有节点必须是相同的Erlang cookie
Queue消息只在一个节点中存储
<span style="color:red">如果Consumer连接Node2，获取Queue1消息，Node2会从Node1获取消息然后返回给Consumer</span>


**二、RabbitMq High Availability**

![](http://dl2.iteye.com/upload/attachment/0128/5740/63ba1134-fb80-394f-9e25-b2128e9b36cb.jpeg)

镜像队列包括一个Master和多个Mirrors，如果Master挂掉时，最老的Mirror晋升为Master，<span style="color:red">还没有从Master复制到Mirrors的消息会丢失</span>
<span style="color:red">Consumer连接到Mirror节点时会让Consumer重定向到Master，Consumer最终只和Master交互</span>，这样保证了消息的先进先出
镜像队列只是提升了<span style="color:red">高可用性</span>，没有分担负载
新晋升的Master会把没有收到ack的消息重新放入队列，包括旧Master没有收到的ack消息，Master收到ack，但是就是Master广播到Mirrors时丢失ack的消息。<span style="color:red">所以Consumer可能会收到重复消息。</span>