mirror of https://github.com/tidwall/tile38.git
MQTT clientId should be unique
Each mqtt hook establishes separate connection to the MQTT broker. If their clientIds are all equal the MQTT broker will disconnect the clients - the protocol does not allow 2 connected clients with the same name
This commit is contained in:
parent
5abadd72a3
commit
fb2aef2ce6
|
@ -83,7 +83,9 @@ func (conn *MQTTConn) Send(msg string) error {
|
|||
}
|
||||
ops = ops.SetTLSConfig(&config)
|
||||
}
|
||||
ops = ops.SetClientID("tile38").AddBroker(uri)
|
||||
nano := time.Now().UnixNano()
|
||||
clientID := fmt.Sprintf("tile38_%x", nano) //the id of connected clients should be unique
|
||||
ops = ops.SetClientID(clientID).AddBroker(uri)
|
||||
c := paho.NewClient(ops)
|
||||
|
||||
if token := c.Connect(); token.Wait() && token.Error() != nil {
|
||||
|
|
Loading…
Reference in New Issue