func InitZK() (*zk.Conn, error) { conn, err := myzk.Connect(Conf.ZookeeperAddr, Conf.ZookeeperTimeout) if err != nil { logger.Errorf("zk.Connect() error(%v)", err) return nil, err } fpath := path.Join(Conf.ZookeeperCometPath, Conf.ZookeeperCometNode) if err = myzk.Create(conn, fpath); err != nil { logger.Errorf("zk.Create() error(%v)", err) return conn, err } // tcp, websocket and rpc bind address store in the zk data := "" for _, addr := range Conf.TCPBind { data += fmt.Sprintf("tcp://%s,", addr) } for _, addr := range Conf.WebsocketBind { data += fmt.Sprintf("ws://%s,", addr) } for _, addr := range Conf.RPCBind { data += fmt.Sprintf("rpc://%s,", addr) } data = strings.TrimRight(data, ",") logger.Tracef("zk data: \"%s\"", data) if err = myzk.RegisterTemp(conn, fpath, data); err != nil { logger.Errorf("zk.RegisterTemp() error(%v)", err) return conn, err } rpc.InitMessage(conn, Conf.ZookeeperMessagePath, Conf.RPCRetry, Conf.RPCPing) return conn, nil }
// InitZK create zookeeper root path, and register a temp node. func InitZK() (*zk.Conn, error) { conn, err := myzk.Connect(Conf.ZookeeperAddr, Conf.ZookeeperTimeout) if err != nil { logger.Errorf("zk.Connect() error(%v)", err) return nil, err } if err = myzk.Create(conn, Conf.ZookeeperPath); err != nil { logger.Errorf("zk.Create() error(%v)", err) return conn, err } data := strings.Join(Conf.RPCBind, ",") logger.Tracef("zk data: \"%s\"", data) // tcp, websocket and rpc bind address store in the zk if err = myzk.RegisterTemp(conn, Conf.ZookeeperPath, data); err != nil { logger.Errorf("zk.RegisterTemp() error(%v)", err) return conn, err } return conn, nil }