func (c *MqttClient) ForceDisconnect() { if c.internalClient == nil || !c.internalClient.IsConnected() { log.Warn("Already closed mqtt-server") return } c.internalClient.ForceDisconnect() log.Infof("ForceDisconnect mqtt-server: %v", c.setting.URL) }
func (db *sqlxDB) CloseDB() error { if db == nil || db.Dbm == nil { return fmt.Errorf("Already closed db") } if err := db.Dbm.Close(); err != nil { log.Warn("Failed to close Database !") } else { log.Info("Close Database !") } return nil }
func (txn *sqlxTxn) Rollback() error { if txn.Tx == nil { return nil } log.Warn("sqlx#Rollback") if err := txn.Tx.Rollback(); err != nil { log.Error("Failed to rollback-transaction %v", err) return err } txn.Dbm = nil return nil }
func (txn *gormTxn) Rollback() error { if txn.Dbm == nil { return nil } log.Warn("gorm#Rollback") if err := txn.Dbm.Rollback().Error; err != nil { log.Error("Failed to rollback-transaction %v", err) return err } txn.Dbm = nil return nil }
func (c *MqttClient) Connect() error { if c.internalClient == nil { return fmt.Errorf("Already closed mqtt-server") } if c.internalClient.IsConnected() { log.Warn("Already connected mqtt-server") return nil } token := c.internalClient.Connect() if token.Wait() && token.Error() != nil { return fmt.Errorf("Failed to connect mqtt-server: %v", token.Error()) } time.Sleep(2 * time.Second) log.Infof("Connect mqtt-server: %v", c.setting.URL) return nil }
func (c *MqttClient) Subscribe(topic string, qos QoS, callback SubscribeMessageHandler) error { token := c.internalClient.Subscribe( topic, byte(qos), func(c *mqtt.Client, msg mqtt.Message) { if msg == nil { log.Warn("Subscribe message is nil") return } if err := callback(msg); err != nil { log.Errorf("Failed to subscript mqtt-server: %v", err) return } }, ) if qos != QOS_ZERO { token.Wait() } if token.Error() != nil { return fmt.Errorf("Failed to subscript mqtt-server: %v", token.Error()) } return nil }