英文:
publish to multiple brokers
问题
我想使用https://github.com/eclipse/paho.mqtt.golang来实现一种消息扇出的功能。
我原本期望客户端能够连接并发布到所有的代理服务器,但是我在它们各自的仪表板上只看到它连接到其中一个代理服务器。
tgOpts := mqtt.NewClientOptions()
for _, target := range targets {
tgOpts.AddBroker(target)
}
我需要为每个目标代理服务器创建一个客户端,还是我做错了什么?
英文:
I want to implement some sort of message fanout using https://github.com/eclipse/paho.mqtt.golang.
I was expecting the client to connect and publish to all the brokers. But I can see in their respective dashboards that it just connects to 1 of those brokers.
tgOpts := mqtt.NewClientOptions()
for _, target := range targets {
tgOpts.AddBroker(target)
}
Do I have to create one client per target broker, or am I doing something wrong?
答案1
得分: 2
MQTT是一种基于主题的模型,一个代理(broker)可以有多个客户端,而不是反过来。
一些代理(例如mosquitto)支持桥接,可以在代理之间建立一个扇出(fanout)的设置,但这个设置是在代理级别上进行的,核心的MQTT功能仍然是一个代理对应一个客户端连接。如果你想要向多个代理发布消息,你需要连接到每个代理并逐个发布。
英文:
MQTT is a topic-based model, 1 broker has multiple clients, not the other way around.
Some brokers (e.g. mosquitto) support bridging, which allows to build a fanout setup across brokers, but this setup is at broker level, the core MQTT functionality is still 1 broker per client connection. If you want to publish to multiple brokers, you'd need to connect to each one and publish individually.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论