负载均衡器在 RabbitMQ 中的工作原理
How load balancer works in RabbitMQ
我是 RabbitMQ 的新手,所以请原谅我的小问题:
1) 在 RabbitMQ 集群的情况下,如果一个节点发生故障,负载转移到另一个节点(不停止其他节点)。同样,我们也可以在不停止集群中现有节点的情况下向现有集群添加新的新鲜节点。对吗?
2) 假设我们从单个 rabbitMQ 节点开始,并在其上创建 100 个队列。现在生产者开始以更快的速度发送消息。为了处理这种负载,我们添加了更多节点并创建了一个集群。但是队列只存在于第一个节点上。现在如何在节点之间进行负载均衡?如果我们需要添加更多队列,我们应该在哪个节点上添加它们?或者我们可以使用负载均衡器添加它们。
提前致谢
1) In case of clustering in RabbitMQ, if a node fails, load shift to another node (without stopping the other nodes). Similarly, we can also add new fresh nodes to the existing cluster without stopping existing nodes in cluster. Is that correct?
如果创建队列的节点发生故障,只要启用了队列镜像,rabbitmq 就会在集群中为该队列选举一个新的主节点。集群根据您可以定义的策略提供 HA。
2) Assume that we start with a single rabbitMQ node, and create 100 queues on it. Now producers started sending message at faster rate. To handle this load, we add more nodes and make a cluster. But queues exist on first node only. How does load balanced among nodes now?
负载不均衡。分布式集群提供 HA 而不是负载平衡。您的请求将被重定向到队列所在的集群中的节点。
And if we need to add more queues, on which node we should add them? Or can we add them using load balancer.
这取决于您的用例。有些人使用循环法并在单独的节点上创建队列。
总结
- 为了 HA,请在集群中使用 mirroring。
- 要平衡节点间的负载,请使用 LB to distribute across Queues。
- 如果您想对队列本身进行负载平衡,请查看 Federated Queues。它们允许您从上游队列获取下游队列上的消息。
让我试着回答你的问题,这通常是大多数开发人员可能会遇到的问题。
问题1)在RabbitMQ集群的情况下,如果一个节点发生故障,负载转移到另一个节点(不停止其他节点)。同样,我们也可以在不停止集群中现有节点的情况下向现有集群添加新的新鲜节点。对吗?
Answer: absolutely correct(if rabbitMQ running on a single host) but rabbitMQ's Queue behaves differently on the cluster. Queues only live on one node in the cluster by default. But Rabbit(2.6.0)
gave us a built-in active-active redundancy option for queues: mirrored queues
. Declaring a mirrored queue is just like declaring a normal queue; you pass an extra argument called x-ha-policy
; tells Rabbit that you want the queue to be mirrored across all nodes in the cluster. This means that if a new node is added to the cluster after the queue is declared, it’ll automatically begin hosting a slave copy of the queue.
问题 2)假设我们从单个 rabbitMQ 节点开始,并在其上创建 100 个队列。现在生产者开始以更快的速度发送消息。为了处理这种负载,我们添加了更多节点并创建了一个集群。但是队列只存在于第一个节点上。现在如何在节点之间进行负载均衡?如果我们需要添加更多队列,我们应该在哪个节点上添加它们?或者我们可以使用负载平衡器添加它们。
这个问题有多个子问题。
How does load-balanced among nodes now?
Set to all, x-ha-policy tells Rabbit that you want the queue to be mirrored across all nodes in the cluster. This means that if a new node is added to the cluster after the queue is declared, it’ll automatically begin hosting a slave copy of the queue.
on which node we should add them?
answer the above.
can we add them using load balancer?
No but yes(you have to call the rabbitMQ API within LB which is not a best practice approach), Load balancer is used for resilient messaging infrastructure. Your cluster nodes are the servers behind the load balancer and your producers and consumers are the customers.
我是 RabbitMQ 的新手,所以请原谅我的小问题:
1) 在 RabbitMQ 集群的情况下,如果一个节点发生故障,负载转移到另一个节点(不停止其他节点)。同样,我们也可以在不停止集群中现有节点的情况下向现有集群添加新的新鲜节点。对吗?
2) 假设我们从单个 rabbitMQ 节点开始,并在其上创建 100 个队列。现在生产者开始以更快的速度发送消息。为了处理这种负载,我们添加了更多节点并创建了一个集群。但是队列只存在于第一个节点上。现在如何在节点之间进行负载均衡?如果我们需要添加更多队列,我们应该在哪个节点上添加它们?或者我们可以使用负载均衡器添加它们。
提前致谢
1) In case of clustering in RabbitMQ, if a node fails, load shift to another node (without stopping the other nodes). Similarly, we can also add new fresh nodes to the existing cluster without stopping existing nodes in cluster. Is that correct?
如果创建队列的节点发生故障,只要启用了队列镜像,rabbitmq 就会在集群中为该队列选举一个新的主节点。集群根据您可以定义的策略提供 HA。
2) Assume that we start with a single rabbitMQ node, and create 100 queues on it. Now producers started sending message at faster rate. To handle this load, we add more nodes and make a cluster. But queues exist on first node only. How does load balanced among nodes now?
负载不均衡。分布式集群提供 HA 而不是负载平衡。您的请求将被重定向到队列所在的集群中的节点。
And if we need to add more queues, on which node we should add them? Or can we add them using load balancer.
这取决于您的用例。有些人使用循环法并在单独的节点上创建队列。
总结
- 为了 HA,请在集群中使用 mirroring。
- 要平衡节点间的负载,请使用 LB to distribute across Queues。
- 如果您想对队列本身进行负载平衡,请查看 Federated Queues。它们允许您从上游队列获取下游队列上的消息。
让我试着回答你的问题,这通常是大多数开发人员可能会遇到的问题。
问题1)在RabbitMQ集群的情况下,如果一个节点发生故障,负载转移到另一个节点(不停止其他节点)。同样,我们也可以在不停止集群中现有节点的情况下向现有集群添加新的新鲜节点。对吗?
Answer: absolutely correct(if rabbitMQ running on a single host) but rabbitMQ's Queue behaves differently on the cluster. Queues only live on one node in the cluster by default. But
Rabbit(2.6.0)
gave us a built-in active-active redundancy option for queues:mirrored queues
. Declaring a mirrored queue is just like declaring a normal queue; you pass an extra argument calledx-ha-policy
; tells Rabbit that you want the queue to be mirrored across all nodes in the cluster. This means that if a new node is added to the cluster after the queue is declared, it’ll automatically begin hosting a slave copy of the queue.
问题 2)假设我们从单个 rabbitMQ 节点开始,并在其上创建 100 个队列。现在生产者开始以更快的速度发送消息。为了处理这种负载,我们添加了更多节点并创建了一个集群。但是队列只存在于第一个节点上。现在如何在节点之间进行负载均衡?如果我们需要添加更多队列,我们应该在哪个节点上添加它们?或者我们可以使用负载平衡器添加它们。
这个问题有多个子问题。
How does load-balanced among nodes now?
Set to all, x-ha-policy tells Rabbit that you want the queue to be mirrored across all nodes in the cluster. This means that if a new node is added to the cluster after the queue is declared, it’ll automatically begin hosting a slave copy of the queue.
on which node we should add them?
answer the above.
can we add them using load balancer?
No but yes(you have to call the rabbitMQ API within LB which is not a best practice approach), Load balancer is used for resilient messaging infrastructure. Your cluster nodes are the servers behind the load balancer and your producers and consumers are the customers.