File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,22 @@ func main() {
3939 opts .SetKeepAlive (2 * time .Second )
4040 opts .SetDefaultPublishHandler (f )
4141 opts .SetPingTimeout (1 * time .Second )
42+ opts .SetConnectionNotificationHandler (func (client mqtt.Client , notification mqtt.ConnectionNotification ) {
43+ switch n := notification .(type ) {
44+ case mqtt.ConnectionNotificationConnected :
45+ fmt .Printf ("[NOTIFICATION] connected\n " )
46+ case mqtt.ConnectionNotificationConnecting :
47+ fmt .Printf ("[NOTIFICATION] connecting (isReconnect=%t) [%d]\n " , n .IsReconnect , n .Attempt )
48+ case mqtt.ConnectionNotificationFailed :
49+ fmt .Printf ("[NOTIFICATION] connection failed: %v\n " , n .Reason )
50+ case mqtt.ConnectionNotificationLost :
51+ fmt .Printf ("[NOTIFICATION] connection lost: %v\n " , n .Reason )
52+ case mqtt.ConnectionNotificationBroker :
53+ fmt .Printf ("[NOTIFICATION] broker connection: %s\n " , n .Broker .String ())
54+ case mqtt.ConnectionNotificationBrokerFailed :
55+ fmt .Printf ("[NOTIFICATION] broker connection failed: %v [%s]\n " , n .Reason , n .Broker .String ())
56+ }
57+ })
4258
4359 c := mqtt .NewClient (opts )
4460 if token := c .Connect (); token .Wait () && token .Error () != nil {
You can’t perform that action at this time.
0 commit comments