|
@@ -56,13 +56,19 @@ func initMqttClient(conf *MqttConfig) (mc MQTT.Client, err error) {
|
|
|
opts.AddBroker(broker)
|
|
|
}
|
|
|
opts.SetClientID(fmt.Sprintf("%s_%s", conf.ClientId, guid.S())).
|
|
|
- SetUsername(conf.User).SetPassword(conf.Password).
|
|
|
- SetConnectRetry(true).SetCleanSession(true)
|
|
|
+ SetUsername(conf.User).
|
|
|
+ SetPassword(conf.Password).
|
|
|
+ SetConnectRetry(true).
|
|
|
+ SetCleanSession(true).
|
|
|
+ SetKeepAlive(120)
|
|
|
opts.SetConnectionAttemptHandler(func(broker *url.URL, tlsCfg *tls.Config) *tls.Config {
|
|
|
server.Log.Infof("connect to %s", broker.String())
|
|
|
return tlsCfg
|
|
|
})
|
|
|
opts.SetOnConnectHandler(func(client MQTT.Client) {
|
|
|
+ if mqttSetOnConnectHandler != nil {
|
|
|
+ mqttSetOnConnectHandler(client)
|
|
|
+ }
|
|
|
server.Log.Infof("connected success")
|
|
|
})
|
|
|
|