|
@@ -38,7 +38,7 @@ func setMqOptions(user, password string, opts *mqtt.ClientOptions) {
|
|
|
}
|
|
|
|
|
|
// SetupMQTT creates a connection to broker and return client
|
|
|
-func SetupMQTT() {
|
|
|
+func SetupMQTT(fatal bool) {
|
|
|
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
|
|
|
if emqx.GetType() == servercfg.EmqxOnPremDeploy {
|
|
|
time.Sleep(10 * time.Second) // wait for the REST endpoint to be ready
|
|
@@ -95,7 +95,7 @@ func SetupMQTT() {
|
|
|
slog.Warn("detected broker connection lost", "err", e.Error())
|
|
|
c.Disconnect(250)
|
|
|
slog.Info("re-initiating MQ connection")
|
|
|
- SetupMQTT()
|
|
|
+ SetupMQTT(false)
|
|
|
|
|
|
})
|
|
|
mqclient = mqtt.NewClient(opts)
|
|
@@ -105,8 +105,15 @@ func SetupMQTT() {
|
|
|
logger.Log(2, "unable to connect to broker, retrying ...")
|
|
|
if time.Now().After(tperiod) {
|
|
|
if token.Error() == nil {
|
|
|
- logger.FatalLog("could not connect to broker, token timeout, exiting ...")
|
|
|
+ if fatal {
|
|
|
+ logger.FatalLog("could not connect to broker, token timeout, exiting ...")
|
|
|
+ }
|
|
|
+ logger.Log(0, "could not connect to broker, token timeout, exiting ...")
|
|
|
+
|
|
|
} else {
|
|
|
+ if fatal {
|
|
|
+ logger.FatalLog("could not connect to broker, exiting ...", token.Error().Error())
|
|
|
+ }
|
|
|
logger.FatalLog("could not connect to broker, exiting ...", token.Error().Error())
|
|
|
}
|
|
|
}
|