mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-09 22:55:02 +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"
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
"golang.org/x/exp/slog"
|
||||
)
|
||||
|
||||
// KEEPALIVE_TIMEOUT - time in seconds for timeout
|
||||
|
@ -91,6 +92,13 @@ func SetupMQTT() {
|
|||
opts.SetOrderMatters(false)
|
||||
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)
|
||||
tperiod := time.Now().Add(10 * time.Second)
|
||||
for {
|
||||
|
|
Loading…
Add table
Reference in a new issue