-
Notifications
You must be signed in to change notification settings - Fork 556
Open
Description
Hi everyone, I’m facing an issue where I get disconnected after connecting. In my code, I’ve implemented logic to reconnect if it gets disconnected, but it keeps disconnecting again.
I need to subscribe to multiple topics and process their payloads. Could someone please help me out?
go func() {
for {
if !client.IsConnectionOpen() {
fmt.Println("Client is not connected!")
token := client.Connect()
token.Wait()
} else {
fmt.Println("mqtt is connect :)")
}
time.Sleep(1 * time.Second)
}
}()
or in publish
if mqttClient.IsConnectionOpen() {
tokenContent := mqttClient.Publish(contentTopic, byte(0), false, string(deCodeBase64))
tokenContent.Wait()
} else {
fmt.Println("mqtt connect fail 4")
ConnectWait := mqttClient.Connect()
ConnectWait.Wait()
fmt.Println("connect after fail 4 successfully")
tokenContent := mqttClient.Publish(contentTopic, byte(0), false, string(deCodeBase64))
tokenContent.Wait()
}
Metadata
Metadata
Assignees
Labels
No labels