예제 #1
0
파일: zk.go 프로젝트: ljvblfz/slot-golang
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
파일: zk.go 프로젝트: ljvblfz/slot-golang
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
}