如何在直接交换上向所有具有相同队列名称/路由键值的订阅者广播

发布于 2024-09-07 07:46:04 字数 279 浏览 2 评论 0原文

考虑一个由 N 多个订阅者组成的层,所有订阅者都使用相同的队列名称和路由键值连接到直接交换器。这将创建一个负载平衡系统,其中入站消息将循环发送到其中 1 个订阅者。这对于处理横向扩展问题非常有效,因为随着负载的增加可以添加更多订阅者,并且在必要时可以稍后撤回。

现在考虑能够向该层中的所有订阅者发送消息的要求,而不知道有多少订阅者(例如“重置您的状态”或“请立即关闭”管理消息)。在rabbitmq中有什么办法可以做到这一点吗?如果这不可能,是否有更好的方法?

我的环境是使用 amqplib 的 Python。

Consider a tier of N-many subscribers, all connected to a direct exchange using identical queue name and routing key values. This creates a load-balanced system where an inbound message is send round-robin to 1 of the subscribers. This works very well for dealing with scale-out issues as more subscribers can be added as load increases and can later be withdrawn if necessary.

Now consider the requirement of being able to send messages to ALL subscribers in that tier, without knowing how many there are (for example a "reset your state" or "shutdown now please" administrative message). Is there any way to do this in rabbitmq? If this isn't possible, is there a better approach?

My environment is Python using amqplib.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城泪 2024-09-14 07:46:04

如果我理解正确的话,这就是你的设置:

  • 你有一个生产者发布到直接交换;
  • 您有一个绑定到该交换器的队列;
  • 你有很多订阅者,都从上面的队列中消费。

这非常适合向任意订阅者发送消息(从而实现负载平衡),但您希望能够向所有订阅者发送一些消息。

您可以通过扇出交换器和每个订阅者的额外队列来做到这一点:

  • 您的生产者将系统范围的消息发布到扇出交换器;
  • 每个绑定到该交换机的订阅者都有一个队列;
  • 每个订阅者首先尝试从该队列中消费;如果不成功,它会尝试从您当前使用的公共队列中进行消费。

If I understand correctly, this is your setup:

  • you have a producer publishing to a direct exchange;
  • you have a queue bound to that exchange;
  • you have many subscribers, all consuming from the above queue.

This works perfectly for sending a message to an arbitrary subscriber (thus sort-of load balancing), but you want to be able to send some messages to ALL the subscribers.

You could do this with a fanout exchange and an extra queue for each subscriber:

  • your producer publishes system-wide messages to a fanout exchange;
  • there's a queue for each subscriber bound to that exchange;
  • each subscriber first attempts to consume from this queue; if it doesn't succeed, it tries to consume from the common queue you currently use.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文