如何在MQTT 5中以共享订阅定位特定工作人员? [英] How to target specific workers with shared subscriptions in MQTT 5?
问题描述
MQTT 5的新功能之一是共享订阅功能,该功能允许在多个工作程序之间进行客户端负载平衡,以便多个工作程序可以负责处理消息,但是每条消息都是仅发送到单个服务器.
One of the new features of MQTT 5 is the shared subscriptions feature, which allows client-side load balancing between multiple workers, so that multiple workers can be responsible for handling messages, but every message is only ever sent to a single server.
默认情况下,这与循环方法一起使用,但是我需要稍微高级一点的方案:
By default, this works with a round-robin approach, but I am in the need of a slightly more advanced scenario:
我想要的是某种路由,以便将消息的属性之一用作某种路由键.即,我希望多个工作人员负责这些消息,但是所有在其路由键属性中具有值X
的消息都应始终发送给同一工作人员,而所有具有Y
的消息也应负责. X
和Y
的工作程序可能有所不同,但所有带有X
的消息都应始终指向同一消息.
What I want is some kind of routing, so that one of the messages' properties gets used as some kind of routing key. I.e., I want multiple workers to be responsible for the messages, but all messages with value X
in their routing key property should always go to the same worker, and all messages with Y
should do as well. The workers for X
and Y
may be different, but all messages with X
should always go to the same one.
问题1:MQTT 5甚至可以做到吗?如果是这样,我需要寻找什么用语?我为此尝试了Google搜索,但并没有真正成功(主要是因为我不知道要查找的内容).
现在,假设这是可能的:那么我该如何处理节点加入或离开的情况?然后,我仍然只希望由一个节点负责,因此如果分配不是静态的,而是可以动态调整的(最好是自动调整自身),那就太好了.但是,我绝对需要避免的是,两个带有X
的消息都同时发送到不同的服务器.
Now, supposed this is possible: How can I then handle cases where nodes join or leave? Then I still want only a single node to be responsible, so it would be great if the assignment was not statically, but could be adjusted dynamically (or even better, would adjust itself automatically). However, what I strictly need to avoid is that two messages with X
ever go to different servers at the same time.
问题2:应该,这是不可能的-我需要MQTT 5的哪些替代方案?
推荐答案
您不在协议级别.这就是共享订阅的全部意义,以便在所有订阅者之间平均分配传入消息.
You don't at a protocol level. That is the whole point of a shared subscription to distribute the incoming messages evenly across all the subscribers.
这也违反了pub/sub范式,即消息是发布到主题而不是单个订阅者的.
This also goes against the pub/sub paradigm, that messages are published to a topic not an individual subscriber.
如果要以不同的方式路由消息,请将其发布到不同的主题.一旦有需要,客户端就可以根据您的消息的元数据在单独的主题上重新发布消息.
If you want to route messages differently publish them to different topics. There is nothing to stop you republishing a message on a separate topic based on it's meta data once it's been received by a client if needed.
这篇关于如何在MQTT 5中以共享订阅定位特定工作人员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!