added isConnectionOpen to the interface and analysis this during execution

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2024-05-16 12:25:53 +02:00
parent 2223abc2d4
commit 281e3d16a5
No known key found for this signature in database
3 changed files with 18 additions and 9 deletions

View File

@ -221,7 +221,7 @@ func (mms *MqttMonitor) MonitorActiveParticipants() {
log.Println("[app] [Monitor] subscribed to tele/# channels") log.Println("[app] [Monitor] subscribed to tele/# channels")
for !mms.IsTerminated() { for !mms.IsTerminated() {
if !mqttClient.IsConnected() { if !mqttClient.IsConnected() || !mqttClient.IsConnectionOpen() {
log.Println("[app] [Monitor] retry establishing a connection") log.Println("[app] [Monitor] retry establishing a connection")
break // Exit inner loop on disconnect break // Exit inner loop on disconnect
} }

View File

@ -15,6 +15,7 @@ type MockMQTTClient struct {
SubscribeFunc func(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token SubscribeFunc func(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
UnsubscribeFunc func(topics ...string) mqtt.Token UnsubscribeFunc func(topics ...string) mqtt.Token
IsConnectedFunc func() bool IsConnectedFunc func() bool
IsConnectionOpenFunc func() bool
connected bool connected bool
connectedMutex sync.Mutex connectedMutex sync.Mutex
} }
@ -129,3 +130,10 @@ func (m *MockMQTTClient) IsConnected() bool {
m.connectedMutex.Unlock() m.connectedMutex.Unlock()
return connected return connected
} }
func (m *MockMQTTClient) IsConnectionOpen() bool {
m.connectedMutex.Lock()
connected := m.connected
m.connectedMutex.Unlock()
return connected
}

View File

@ -23,6 +23,7 @@ type MQTTClientI interface {
Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
Unsubscribe(topics ...string) mqtt.Token Unsubscribe(topics ...string) mqtt.Token
IsConnected() bool IsConnected() bool
IsConnectionOpen() bool
} }
var ( var (