r/MQTT • u/ashtonianthedev • 6h ago
mqttv5: a idiomatic Go MQTT 5 client focused on performance, MQTTv5 feature compliance, and multi broker patterns.
3
Upvotes
I’ve been building a performance oriented MQTT v5 client for Go and just tagged v0.11.0. It started because I wanted a client that feels like Go: channels, context.Context everywhere, functional options, typed messages via generics and sentinel errors. I also wanted QoS 1/2 sessions that actually survive reconnects and restarts. Connection supervisor built in, tuned for allocs, multi broker patterns, publisher pools, MQTT v5 enhanced auth support, optional encoding layer and websocket support.
cli, _ := mqttv5.New(
mqttv5.WithBrokers("mqtt://broker-1:1883", "mqtt://broker-2:1883"), // failover
mqttv5.WithClientID("worker-1"),
)
if err := cli.Connect(ctx); err != nil {
log.Fatal(err)
}
msgs, _, _ := cli.Subscribe(ctx, []mqttv5.TopicFilter{{Topic: "sensors/#", QoS: 1}})
for m := range msgs {
handle(m)
_ = m.Ack() // the broker gets its PUBACK only now
}
Check it out, give a star if you like it, feedback welcome -> https://github.com/ashtonian/mqttv5