Home > Blockchain >  publish to multiple brokers
publish to multiple brokers

Time:11-10

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?

CodePudding user response:

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.

  • Related