【原创】RabbitMQ 之 Distributed brokers(翻译)

简介:
Distributed RabbitMQ brokers  

AMQP and the other messaging protocols supported by RabbitMQ via plug-ins (e.g. STOMP), are (of course) inherently distributed - it is quite common for applications from multiple machines to connect to a single broker, even across the internet.  
AMQP 协议以及其他的 RabbitMQ 通过插件方式支持的消关协议(例如 STOMP)在本质都是分布式的,因为通过多台机器连接到单个 broker 的应用场景太常见了,即便跨越因特网的连接也是如此。  

Sometimes however it is necessary or desirable to make the RabbitMQ broker itself distributed. There are three ways in which to accomplish that: with clustering, with federation, and using the shovel. This page explains the purpose of each approach.  
然而,有些时候让 RabbitMQ broker 本身具有分布式功能也是非常必要的;目前存在 3 种方式可以达成此目的:基于集群实现,通过 federation 插件实现,以及通过 shovel 插件实现。本节内容针对这几种方式进行解释说明。  

Note that you do not need to pick a single approach - you can connect clusters together with federation, or the shovel, or both.  
需要注意的是,你不是只能使用单一一种方式达成目标,如果你愿意,你可以通过 federation 或/和 shovel 插件连接你的集群;  


Clustering

Clustering connects multiple machines together to form a single logical broker. Communication is via Erlang message-passing, so all nodes in the cluster must have the same Erlang cookie. The network links between machines in a cluster must be reliable, and all machines in the cluster must run the same versions of RabbitMQ and Erlang.  
集群功能   可以将多台机器相互连接形成一个单一的逻辑 broker ;  
集群中的通信方式采用 Erlang 语言自身的消息传递模式,所以集群中的所有节点都必须持有相同的 Erlang cookie 值;  
在同一集群中,各台机器之间的网络连接必须是可靠的;  
集群中的所有机器上必须运行相同版本的 RabbitMQ 和 Erlang ;  

Virtual hosts, exchanges, users, and permissions are automatically mirrored across all nodes in a cluster. Queues may be located on a single node, or mirrored across multiple nodes. A client connecting to any node in a cluster can see all queues in the cluster, even if they are not located on that node.  
vhost, exchange, user 和 permission 等信息会自动复制到集群中的每个节点上;  
queue 稍微特殊一点,你可以认为其位于单独一个节点上,当然,也可以通   镜像队列   方式将 queue 的内容复制到多个节点上;  
连接到集群中的任意节点上的客户端都能够看到属于该集群的全部 queue 信息,即使这些 queue 并不真正位于该节点;  

Typically you would use clustering for high availability and increased throughput, with machines in a single location.  
集群的典型应用场景为需要高可用和增加吞吐量的场合,并且集群中的所有机器位于同一个地点。  

Federation  

Federation allows an exchange or queue on one broker to receive messages published to an exchange or queue on another (the brokers may be individual machines, or clusters). Communication is via AMQP (with optional SSL), so for two exchanges or queues to federate they must be granted appropriate users and permissions.  
Federation 允许从某个 broker 上的 exchange 或 queue 中能够接收到,发向另一个 broker 的 exchange 或 queue 上的消息;  
上面说的 broker 可以是单独的机器,也可以是集群;  
Federation 的实现基于 AMQP 协议(可选增加 SSL),所以成功 federate 两个 exchange 或 queue 的前提是必须设置好适当的 user 和 permission 约束;  

Federated exchanges are connected with one way point-to-point links. By default, messages will only be forwarded over a federation link once, but this can be increased to allow for more complex routing topologies. Some messages may not be forwarded over the link; if a message would not be routed to a queue after reaching the federated exchange, it will not be forwarded in the first place.  
Federated exchange 属于一种单向点对点连接;默认情况下,消息将只能从该 federation link 上转发一次,但是可以增加转发次数以满足更加复杂的路由策略;  
某些消息可能根本不会从该 federation link 上进行转发;  
如果某条消息在到达 federation exchange 后根本不会被路由到 queue 中,那么该消息最初就不会被转发;  

Federated queues are similarly connected with one way point-to-point links. Messages will be moved between federated queues an arbitrary number of times to follow the consumers.  
Federated queue 同样属于一种单向点对点连接;  
消息会在 Federated queue 之间搬移任意多次以 follow 消费者;  

Typically you would use federation to link brokers across the internet for pub/sub messaging and work queueing.  
Federation 的典型应用场景为跨因特网将两个 broker 连接起来,用于消息的 pub/sub 行为,或者用于工作队列模式;  


The Shovel  

Connecting brokers with the shovel is conceptually similar to connecting them with federation. However, the shovel works at a lower level.  
通过 shovel 连接 broker 与通过 federation 连接 broker 在概念上是相似的;   但是 shovel 属于更加底层的应用模型    

Whereas federation aims to provide opinionated distribution of exchanges and queues, the shovel simply consumes messages from a queue on one broker, and forwards them to an exchange on another.  
federation 的设计限制其分布式功能是针对 exchange 和 queue 的;  
而 shovel 的设计只是简单的要求从某个 broker 上的 queue 中消费消息,再转发到另一个 broker 上的 exchange 上;  

Typically you would use the shovel to link brokers across the internet when you need more control than federation provides.  
一般情况下,如果你需要比 federation 所能提供的更多的控制,你就要使用 shovel 来完成跨因特网的 broker 连接了;  

Dynamic shovels can also be useful for moving messages around in an ad-hoc manner on a single broker.  
Dynamic shovel 对于针对同一个 broker 以 ad-hoc 方式搬移消息的场景同样非常有用;  

Summary  

Federation / Shovel
Clustering
Brokers are logically separate and may have different owners.
不同 broker 之间逻辑上是独立的,可能分属不同的 owner ;
A cluster forms a single logical broker.
整个集群构成一个单独的逻辑 broker ;
Brokers can run different versions of RabbitMQ and Erlang.
不同 broker 上可以运行不同版本的 RabbitMQ 和 Erlang ;
Nodes must run the same version of RabbitMQ, and frequently Erlang.
全部节点必须运行相同版本的 RabbitMQ 和 Erlang 版本;
Brokers can be connected via unreliable WAN links. Communication is via AMQP (optionally secured by SSL), requiring appropriate users and permissions to be set up.
broker 之间的连接可以建立在不可靠的 WAN 网上;通信协议采用 AMQP (可选 SSL 加密);需要建立合适的 user 和 permission 设置;
Brokers must be connected via reliable LAN links. Communication is via Erlang internode messaging, requiring a shared Erlang cookie.
broker 之间必须通过可靠的 LAN 网建立连接;通信方式采用 Erlang 的节点内消息发送;要求所有节点共享 Erlang cookie 值;
Brokers can be connected in whatever topology you arrange. Links can be one- or two-way.
broker 之间可以按照任何形式的拓扑结构进行连接;连接可以是单向的或者双向的;
All nodes connect to all other nodes in both directions.
所有节点两两互联,且为双向连接;
Chooses Availability and Partition Tolerance (AP) from the CAP theorem.
基于 CAP 理论中的 AP 实现;
Chooses Consistency and Partition Tolerance (CP) from theCAP theorem.
基于 CAP 理论中的 CP 实现;
Some exchanges in a broker may be federated while some may be local.
broker 中的某些 exchange 可能进行了 federated ,而另外一些可能是本地的;
Clustering is all-or-nothing.
在集群中,所有 fabric 的属性都一致;
A client connecting to any broker can only see queues in that broker.
连接到任意一个 broker 上的客户端只能看到属于该 broker 的 queue 信息;
A client connecting to any node can see queues on all nodes.
连接到集群中的任意节点,都能看到属于集群的所有 queue 信息;




相关实践学习
RocketMQ一站式入门使用
从源码编译、部署broker、部署namesrv,使用java客户端首发消息等一站式入门RocketMQ。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
目录
相关文章
|
消息中间件 Java 物联网
[原创]AMQP-RabbitMQ/1/概念/一对一简单模型
[原创]AMQP-RabbitMQ/1/概念/一对一简单模型
[原创]AMQP-RabbitMQ/1/概念/一对一简单模型
|
消息中间件 缓存 网络安全