From 986c949195d1f50758602f198cae76d56c3b8d56 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期五, 08 一月 2021 18:16:52 +0800
Subject: [PATCH] 如果没有pubTopics或者subTopic,则不启动server接收

---
 hbusc.go |   54 ++++++++++++++++++++++++++++++------------------------
 1 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/hbusc.go b/hbusc.go
index bd7bd29..5831755 100644
--- a/hbusc.go
+++ b/hbusc.go
@@ -192,24 +192,27 @@
 		}
 	}
 
-	handle.wg = &sync.WaitGroup{}
-
-	sockReply := bhomebus.OpenSocket()
-	sockReply.ForceBind(int(regR.ReplyKey))
-	handle.wg.Add(1)
-	//serve server reply
-	go recvRoutine(ctx, sockReply, handle.wg, handle.chReply, handle.printLog)
-	handle.sockRep = &sockServer{
-		sock: sockReply,
-		info: &ri.Proc,
-	}
-
 	//缁存寔蹇冭烦鐨剆ocket
 	sockHB := bhomebus.OpenSocket()
 	handle.sockHB = &sockClient{
 		sock: sockHB,
 		peer: int(regR.HeartbeatKey),
 	}
+
+	handle.wg = &sync.WaitGroup{}
+
+	if ri.PubTopic != nil && len(ri.PubTopic) > 0 {
+		sockReply := bhomebus.OpenSocket()
+		sockReply.ForceBind(int(regR.ReplyKey))
+		handle.wg.Add(1)
+		//serve server reply
+		go recvRoutine(ctx, sockReply, handle.wg, handle.chReply, handle.printLog)
+		handle.sockRep = &sockServer{
+			sock: sockReply,
+			info: &ri.Proc,
+		}
+	}
+
 
 	//鍙戝竷娑堟伅鐨剆ocket, pub鏄皢娑堟伅鍙戝竷鍒癰us涓紝鎵�浠ヤ笉闇�瑕佹寚瀹歬ey
 	sockPub := bhomebus.OpenSocket()
@@ -218,19 +221,22 @@
 		peer: -1,
 	}
 
-	//璁㈤槄娑堟伅鐨剆ocket
-	sockSub := bhomebus.OpenSocket()
-	//璁㈤槄鎵�鏈変富棰�
-	for _,v := range ri.SubTopic {
-		sockSub.Sub(v)
-	}
+	//鏈夎闃呮秷鎭墠闇�瑕佸惎鍔ㄥ崗绋嬫帴鏀舵秷鎭�
+	if ri.SubTopic != nil && len(ri.SubTopic) > 0 {
+		//璁㈤槄娑堟伅鐨剆ocket
+		sockSub := bhomebus.OpenSocket()
+		//璁㈤槄鎵�鏈変富棰�
+		for _,v := range ri.SubTopic {
+			sockSub.Sub(v)
+		}
 
-	//鍚姩璁㈤槄淇℃伅鎺ユ敹
-	handle.wg.Add(1)
-	go recvRoutine(ctx, sockSub, handle.wg, handle.chSub, handle.printLog)
-	handle.sockSub = &sockClient{
-		sock: sockSub,
-		peer: -1,
+		//鍚姩璁㈤槄淇℃伅鎺ユ敹
+		handle.wg.Add(1)
+		go recvRoutine(ctx, sockSub, handle.wg, handle.chSub, handle.printLog)
+		handle.sockSub = &sockClient{
+			sock: sockSub,
+			peer: -1,
+		}
 	}
 
 	sockWorker := bhomebus.OpenSocket()

--
Gitblit v1.8.0