lijian hace 2 años
padre
commit
931c2b52f0
Se han modificado 1 ficheros con 7 adiciones y 5 borrados
  1. 7 5
      pkg/ruleEngine/nodes/mqtt_broker_node.go

+ 7 - 5
pkg/ruleEngine/nodes/mqtt_broker_node.go

@@ -121,11 +121,13 @@ func (M *MQTTBrokerNode) OnMessage(ctx ruleEngine.Context, message *protocol.Mes
 	}
 	topic := stringBuf.String()
 	fmt.Printf("+++++++++++++++%v\r\n", M.mqttClient)
-	token := M.mqttClient.Publish(topic, 0, false, message.Data)
-	if token.Error() != nil {
-		ctx.TellNext(message, protocol.Failure)
-	} else {
-		ctx.TellNext(message, protocol.Success)
+	if M.mqttClient != nil {
+		token := M.mqttClient.Publish(topic, 0, false, message.Data)
+		if token.Error() != nil {
+			ctx.TellNext(message, protocol.Failure)
+		} else {
+			ctx.TellNext(message, protocol.Success)
+		}
 	}
 
 	return nil