mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-10 23:24:32 +08:00
add mq connection lost handler on server
This commit is contained in:
parent
4cae1b0bb4
commit
c82918ad35
1 changed files with 8 additions and 0 deletions
8
mq/mq.go
8
mq/mq.go
|
@ -9,6 +9,7 @@ import (
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"github.com/gravitl/netmaker/logger"
|
"github.com/gravitl/netmaker/logger"
|
||||||
"github.com/gravitl/netmaker/servercfg"
|
"github.com/gravitl/netmaker/servercfg"
|
||||||
|
"golang.org/x/exp/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KEEPALIVE_TIMEOUT - time in seconds for timeout
|
// KEEPALIVE_TIMEOUT - time in seconds for timeout
|
||||||
|
@ -91,6 +92,13 @@ func SetupMQTT() {
|
||||||
opts.SetOrderMatters(false)
|
opts.SetOrderMatters(false)
|
||||||
opts.SetResumeSubs(true)
|
opts.SetResumeSubs(true)
|
||||||
})
|
})
|
||||||
|
opts.SetConnectionLostHandler(func(c mqtt.Client, e error) {
|
||||||
|
slog.Warn("detected broker connection lost", "err", e.Error())
|
||||||
|
c.Disconnect(250)
|
||||||
|
slog.Info("re-initiating MQ connection")
|
||||||
|
SetupMQTT()
|
||||||
|
|
||||||
|
})
|
||||||
mqclient = mqtt.NewClient(opts)
|
mqclient = mqtt.NewClient(opts)
|
||||||
tperiod := time.Now().Add(10 * time.Second)
|
tperiod := time.Now().Add(10 * time.Second)
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Add table
Reference in a new issue