连接管理 MQTT 代理 Kubernetes?

huangapple go评论64阅读模式
英文:

Connection management mqtt broker kubernetes?

问题

我们正在使用 Mosquitto MQTT 代理,这是一种物联网服务器实现,设备会将其作为客户端连接到代理。设备和物联网服务器都会发布消息到代理。

设备会将请求发布到主题:/req/<device-id>/<server-id>

设备会订阅响应:/resp/<device-id>/<server-id>

如果物联网服务器向特定设备发送通知,它会将其发布到通知主题,设备也会订阅该主题:

/req/<server-id>/<device-id>

所以,到目前为止,这种情景运作良好,但我们希望将实现迁移到 Kubernetes 上,以便 MQTT 代理和物联网服务器都可以运行多个 Pod 实例。

现在,任何设备都可以连接到任何 mosquitto Pod 实例,任何 IoT server Pod 都可以连接到 mosquitto Pod 实例。

因此,连接到 mosquitto Pod1 的设备和连接到 IoT server Pod1 的设备,如果 IoT server Pod2 生成通知并将其发送到我们的设备未连接到的 mosquitto Pod 实例,则可能无法接收通知。

因此,IoT server 需要知道哪个设备连接到哪个 Pod 实例,以便发送通知。

Kubernetes 环境中如何实现这一点?

英文:

We are using Mosquitto MQTT broker, an IoT server implementation and devices which connect to the Broker as an Client. Both device and IoT server will be publishing to the broker.

The devices publish requests to the topic : /req/&lt;device-id&gt;/&lt;server-id&gt;

The devices subscribe to responses : /resp/&lt;device-id&gt;/&lt;server-id&gt;

And if IoT server sends a notification to a particular device, it publish to notification topic to which device also subscribes:

/req/&lt;server-id&gt;/&lt;device-id&gt;

连接管理 MQTT 代理 Kubernetes?

So this scenario is working fine uptill now, but we want to shift our implementation on Kubernetes such that both MQTT broker and IoT server will have multiple pods running.

So now any device can connect to any mosquitto pod instance and any IoT server pod would be connecting to mosquitto pod instance.

So a device connected to mosquitto pod1 and IoT server pod1 might not receive notifications if pod2 of IoT server generates notification and sends it to mosquitto pod instance to which our device wasn't connected to.

So IoT server will need the awareness that which device is connected to which pod instance to send notifications.

How to achieve this in Kubernetes environment??

答案1

得分: 1

以下是翻译好的部分:

短期答案是:不容易。

更详细的回答是:

您可能需要选择一个不同于mosquitto的MQTT代理,因为mosquitto不支持集群,所以没有(简单)的方法来运行多个实例以分发会话和消息。

您可以设置多个代理实例之间的桥接,以确保消息最终出现在所有实例上,但最好的方法是使用星形结构,其中有一个“中央”代理,然后将所有消息重新分发到星星各个点上。设备然后连接到这些星形实例。这并不能解决分布式会话的任何问题。

您还可能需要查看共享订阅,以便消息只被物联网服务器的一个实例消耗。

还有一些其他支持适当集群的MQTT代理实现,例如HiveMQ和emqx。

英文:

The short answer to this is: You don't easily.

The longer answer is:

You will probably need to pick a different MQTT broker than mosquitto, mosquitto does not support clustering, so there is no (simple) way to run multiple instances that sessions and messages can be distributed across.

You can setup bridging between multiple broker instances to ensure messages end up on all instances, but the best way to do this is with a star formation, with a "central" broker that then redistributes all the messages to the points of the star. The devices would then connect to the these star instances. This does not solve any of the problems with distributed sessions.

You will also probably need to look at shared subscriptions so that messages are only consumed by a single instance of the IoT Server.

There are several other MQTT broker implementations that support proper clustering, iirc things like HiveMQ and emqx

huangapple
  • 本文由 发表于 2023年6月29日 19:19:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定