如何在直接交换上向所有具有相同队列名称/路由键值的订阅者广播
考虑一个由 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,这就是你的设置:
这非常适合向任意订阅者发送消息(从而实现负载平衡),但您希望能够向所有订阅者发送一些消息。
您可以通过扇出交换器和每个订阅者的额外队列来做到这一点:
If I understand correctly, this is your setup:
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: