mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25: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")
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,14 +9,15 @@ import (
|
|||||||
|
|
||||||
// MockMQTTClient is the mock mqtt client
|
// MockMQTTClient is the mock mqtt client
|
||||||
type MockMQTTClient struct {
|
type MockMQTTClient struct {
|
||||||
ConnectFunc func() mqtt.Token
|
ConnectFunc func() mqtt.Token
|
||||||
DisconnectFunc func(quiesce uint)
|
DisconnectFunc func(quiesce uint)
|
||||||
PublishFunc func(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
|
PublishFunc func(topic string, qos byte, retained bool, payload interface{}) mqtt.Token
|
||||||
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
|
||||||
connected bool
|
IsConnectionOpenFunc func() bool
|
||||||
connectedMutex sync.Mutex
|
connected bool
|
||||||
|
connectedMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConnectFunc fetches the mock client's `Connect` func
|
// GetConnectFunc fetches the mock client's `Connect` func
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
|||||||
@ -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 (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user