mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 14:35:47 +00:00
added isConnectionOpen to the interface and analysis this during execution
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
2223abc2d4
commit
281e3d16a5
@ -221,7 +221,7 @@ func (mms *MqttMonitor) MonitorActiveParticipants() {
|
||||
log.Println("[app] [Monitor] subscribed to tele/# channels")
|
||||
|
||||
for !mms.IsTerminated() {
|
||||
if !mqttClient.IsConnected() {
|
||||
if !mqttClient.IsConnected() || !mqttClient.IsConnectionOpen() {
|
||||
log.Println("[app] [Monitor] retry establishing a connection")
|
||||
break // Exit inner loop on disconnect
|
||||
}
|
||||
|
||||
@ -9,14 +9,15 @@ import (
|
||||
|
||||
// MockMQTTClient is the mock mqtt client
|
||||
type MockMQTTClient struct {
|
||||
ConnectFunc func() mqtt.Token
|
||||
DisconnectFunc func(quiesce uint)
|
||||
PublishFunc func(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
|
||||
SubscribeFunc func(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
|
||||
UnsubscribeFunc func(topics ...string) mqtt.Token
|
||||
IsConnectedFunc func() bool
|
||||
connected bool
|
||||
connectedMutex sync.Mutex
|
||||
ConnectFunc func() mqtt.Token
|
||||
DisconnectFunc func(quiesce uint)
|
||||
PublishFunc func(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
|
||||
SubscribeFunc func(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
|
||||
UnsubscribeFunc func(topics ...string) mqtt.Token
|
||||
IsConnectedFunc func() bool
|
||||
IsConnectionOpenFunc func() bool
|
||||
connected bool
|
||||
connectedMutex sync.Mutex
|
||||
}
|
||||
|
||||
// GetConnectFunc fetches the mock client's `Connect` func
|
||||
@ -129,3 +130,10 @@ func (m *MockMQTTClient) IsConnected() bool {
|
||||
m.connectedMutex.Unlock()
|
||||
return connected
|
||||
}
|
||||
|
||||
func (m *MockMQTTClient) IsConnectionOpen() bool {
|
||||
m.connectedMutex.Lock()
|
||||
connected := m.connected
|
||||
m.connectedMutex.Unlock()
|
||||
return connected
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ type MQTTClientI interface {
|
||||
Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
|
||||
Unsubscribe(topics ...string) mqtt.Token
|
||||
IsConnected() bool
|
||||
IsConnectionOpen() bool
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user