From 38eccdf006c8374e89b7b7bb816b2d4ce4b2a220 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期二, 14 一月 2020 20:31:34 +0800 Subject: [PATCH] fix msg send --- mangos.go | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mangos.go b/mangos.go index a194c2e..47a9b0d 100644 --- a/mangos.go +++ b/mangos.go @@ -12,6 +12,7 @@ heartBeatUrl string pubCh chan Message //publish msg chan aliveNodes gopherdiscovery.StringSet + clients map[string][]string recvCh chan Message //recv msg chan } @@ -36,6 +37,7 @@ heartBeatUrl: heartBeatUrl, aliveNodes: gopherdiscovery.NewStringSet(), pubCh: make(chan Message, 50), + clients: make(map[string][]string), } var msgCache = make(map[string]Message) //clientMsgCh := make(map[string]chan Message) @@ -62,9 +64,11 @@ // clientMsgCh[nodeId] = make(chan Message) // } //} + removedNodes := cacheNodes.Difference(nodeIds) + addedNodes := nodeIds.Difference(cacheNodes) if len(nodeIds.ToSlice()) >0 { - if len(nodeIds.Difference(cacheNodes).ToSlice()) > 0 { //鑺傜偣鏈夊彉鍖栫殑鏃跺�欙紝涔熼渶瑕佸彂娑堟伅 - fmt.Println("aliveNodes:",nodeIds) + if removedNodes.Cardinality() >0 || addedNodes.Cardinality() >0 { //鑺傜偣鏈夊彉鍖栫殑鏃跺�欙紝涔熼渶瑕佸彂娑堟伅 + fmt.Println("removedNodes:", removedNodes, "addedNodes:", addedNodes) if len(msgCache) > 0 { for _,cMsg := range msgCache { sendB, _ := json.Marshal(cMsg) @@ -72,9 +76,9 @@ } } } - cacheNodes = discoveryServer.AliveNodes() + cacheNodes = nodeIds } else {//璁㈤槄鑰呭叏閮ㄩ樀浜� - cacheNodes = discoveryServer.AliveNodes() + cacheNodes = nodeIds time.Sleep(10 * time.Millisecond) } } -- Gitblit v1.8.0