From 1bfbe354f54775efa012967569b5be3507eb9dc8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 23 Feb 2022 20:19:59 -0800 Subject: [PATCH] fix: clientId must be unique for all servers (#14398) This is a regression from #14037, distributed setups with MQTT was not working anymore. According to MQTT spec it is expected this is unique per server. We shall proceed to use unix nano timestamp hex value instead here. --- internal/event/target/mqtt.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/event/target/mqtt.go b/internal/event/target/mqtt.go index 0448a383f..82e5809a8 100644 --- a/internal/event/target/mqtt.go +++ b/internal/event/target/mqtt.go @@ -213,8 +213,13 @@ func NewMQTTTarget(id string, args MQTTArgs, doneCh <-chan struct{}, loggerOnce args.KeepAlive = 10 * time.Second } + // Using hex here, to make sure we avoid 23 + // character limit on client_id according to + // MQTT spec. + clientID := fmt.Sprintf("%x", time.Now().UnixNano()) + options := mqtt.NewClientOptions(). - SetClientID(id). + SetClientID(clientID). SetCleanSession(true). SetUsername(args.User). SetPassword(args.Password).