Пример #1
0
func watchEvent(event zookeeper.Event) {
	if !zkOk.Get() {
		return
	}
	if event.State == zookeeper.StateHasSession {
		err := zk.CreateTempW(zkConn, zkRoot, zkListenAddr, watchZK)
		if err == nil {
			glog.Infof("[zk] register msgbus node ok")
		} else {
			glog.Errorf("[zk] write msgbus node on zookeeper.StateHasSession failed, error: %v", err)
		}
	}
}
Пример #2
0
func InitZK(addrs []string, listenAddr string, rootName string, rmqRoot string) error {
	conn, err := zk.Connect(addrs, 60*time.Second, watchEvent)
	if err != nil {
		return err
	}
	zkRoot = "/" + rootName
	zkConn = conn
	zkListenAddr = listenAddr

	zk.Create(conn, zkRoot)
	glog.Infof("Connect zk[%v] on msgbus root [%s] OK!", addrs, rootName)
	createErr := zk.CreateTempW(conn, zkRoot, listenAddr, watchZK)
	zkOk.Set(true)
	if createErr != nil {
		return createErr
	}

	go WatchRmq(rmqRoot)
	return nil
}