Browse Source

优化代码注释

niujiuru 24 minutes ago
parent
commit
f918184fa7
1 changed files with 1 additions and 4 deletions
  1. 1 4
      mqtt_reporter/client.go

+ 1 - 4
mqtt_reporter/client.go

@@ -75,6 +75,7 @@ func NewClient(config ClientConfig, ctx context.Context) (*Client, error) {
 		SetUsername(config.Username).SetPassword(config.Password).SetClientID(config.ClientID).
 		SetConnectRetry(false).SetAutoReconnect(false).SetCleanSession(true).
 		SetKeepAlive(10 * time.Second).SetPingTimeout(5 * time.Second). // 保活超时&Ping心跳间隔
+		// 下面的设置使得回调独立 goroutine 执行, 避免阻塞 MQTT 网络处理 /////////////////////////
 		SetOrderMatters(false)
 
 	if willTopic := config.Topics["Offline"]; willTopic != "" { // 设置遗嘱消息
@@ -285,10 +286,6 @@ func (c *Client) Publish(topic string, qos byte, retained bool, payload any) err
 	return c.waitToken(token)
 }
 
-/*
-消息回调需支持并发调用,并尽快返回,尽量避免耗时或阻塞操作, 此类类任务应交由独立的goroutine或通
-过消息队列来处理,避免阻塞mqtt底层的消息处理。
-*/
 func (c *Client) Subscribe(topic string, qos byte, handler MessageHandler) error {
 	if topic == "" {
 		return ErrTopicEmpty