func NewNsqdEtcdMgr(host string) *NsqdEtcdMgr { client := etcdlock.NewEClient(host) return &NsqdEtcdMgr{ client: client, //topicLockMap: make(map[string]*etcdlock.SeizeLock), } }
func NewNsqLookupdEtcdMgr(host string) *NsqLookupdEtcdMgr { client := etcdlock.NewEClient(host) return &NsqLookupdEtcdMgr{ client: client, ifTopicChanged: 1, watchTopicLeaderStopCh: make(chan bool, 1), watchTopicsStopCh: make(chan bool, 1), watchNsqdNodesStopCh: make(chan bool, 1), topicMetaMap: make(map[string]*TopicMetaInfo), watchTopicLeaderChanMap: make(map[string]*WatchTopicLeaderInfo), watchTopicLeaderEventChan: make(chan *WatchTopicLeaderInfo, 1), refreshStopCh: make(chan bool, 1), } }
func TestETCDWatch(t *testing.T) { client := etcdlock.NewEClient(testEtcdServers) watcher := client.Watch("q11", 0, true) ctx, cancel := context.WithCancel(context.Background()) go func() { time.Sleep(10 * time.Second) cancel() }() for { rsp, err := watcher.Next(ctx) if err != nil { if err == context.Canceled { fmt.Println("watch canceled") return } else { time.Sleep(5 * time.Second) } continue } fmt.Println(rsp.Action, rsp.Node.Key, rsp.Node.Value) } }