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.
This commit is contained in:
Harshavardhana 2022-02-23 20:19:59 -08:00 committed by GitHub
parent 2d78e20120
commit 1bfbe354f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -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).