| | |
| | | // ch <- msg |
| | | // } |
| | | //} |
| | | fmt.Println("<-pub.pubCh,pub.surveyors.Len:",pub.surveyors.Cardinality()) |
| | | if pub.surveyors.Cardinality() >0 { |
| | | sendB, _ := json.Marshal(msg) |
| | | discoveryServer.PublishMsg(string(sendB)) |
| | |
| | | //} |
| | | removedNodes := pub.surveyors.Difference(nodeIds) |
| | | addedNodes := nodeIds.Difference(pub.surveyors) |
| | | if len(nodeIds.ToSlice()) >0 { |
| | | if addedNodes.Cardinality() >0 { //有新节点上线的时候,需要发一次消息,节点离线的时候不用管 |
| | | fmt.Println("removedNodes:", removedNodes, "addedNodes:", addedNodes) |
| | | if len(msgCache) > 0 { |
| | | for _,cMsg := range msgCache { |
| | | sendB, _ := json.Marshal(cMsg) |
| | | discoveryServer.PublishMsg(string(sendB)) |
| | | } |
| | | |
| | | if addedNodes.Cardinality() >0 { //有新节点上线的时候,需要发一次消息,节点离线的时候不用管 |
| | | fmt.Println("removedNodes:", removedNodes, "addedNodes:", addedNodes) |
| | | if len(msgCache) > 0 { |
| | | for _,cMsg := range msgCache { |
| | | sendB, _ := json.Marshal(cMsg) |
| | | discoveryServer.PublishMsg(string(sendB)) |
| | | } |
| | | } |
| | | pub.surveyors = nodeIds |
| | | } else {//订阅者全部阵亡 |
| | | pub.surveyors = nodeIds |
| | | time.Sleep(10 * time.Millisecond) |
| | | } |
| | | |
| | | pub.surveyors = nodeIds |
| | | time.Sleep(10 * time.Millisecond) |
| | | } |
| | | } |
| | | }() |