rabbitmq - Azure 服务总线、AWS SNS、RabbitMQ -> 所有订阅者都收到消息?
问题描述
在查看 Pub/Sub 模式时,我遇到了这样的场景:
假设您有一个水平缩放的应用程序,它有 X 个实例。他们都订阅了一个主题,其中包含“将 10 美元从账户 A 转移到账户 B”之类的消息。当有人向该主题发布消息时,所有订阅者都会收到该消息吗?
在上述情况下,很明显,消息应该只被 1 个订阅者接收并且只处理一次。
如何处理这种情况?您是否放弃发布/订阅并开始合并?
解决方案
In RabbitMQ Normally, active consumers connected to the same queue receive messages from it in a round-robin fashion. So this insures that a message is processed exactly once.
So in your case you should design a queue where all the messages for
"Transfer $10 from account A to account B"
Are routed to and all the consumers register themselves on this queue itself , this insures that one message will go to only one subscriber.
Another point not related to your question but is important to know is that there is another concept called "Consumer Priorities" which allows you to ensure that high priority consumers receive messages while they are active, with messages only going to lower priority consumers when the high priority consumers block.
More info can be found here
推荐阅读
- java - 当提供的 json 的类类型与目标类不同时,杰克逊不会在反序列化时抛出异常
- scala - 未满足 Macwire 依赖项
- laravel - 如何编写 Laravel 7 嵌套查询?
- c - 获取指定索引之间的数组的子数组
- python - 在 Python 中使用两个单独的线程打印偶数和奇数
- keras - keras fit 的输出是否显示平均损失?
- python - 如何正确规范我的嵌套 json?
- angular - NativeScript如何动态更新视图?
- c# - 你如何使用哈希集
在 C# 中使用二进制阅读器 - python - 如何将“askopenfilename”文件路径解析为另一个函数?