func InitZK() (*zk.Conn, error) { conn, err := myzk.Connect(Conf.ZookeeperAddr, Conf.ZookeeperTimeout) if err != nil { log.Error("myzk.Connect() error(%v)", err) return nil, err } fpath := path.Join(Conf.ZookeeperCometPath, Conf.ZookeeperCometNode) if err = myzk.Create(conn, fpath); err != nil { log.Error("myzk.Create(conn,\"%s\",\"\") error(%v)", fpath, err) return conn, err } // comet tcp, websocket and rpc bind address store in the zk nodeInfo := &rpc.CometNodeInfo{} nodeInfo.RpcAddr = Conf.RPCBind nodeInfo.TcpAddr = Conf.TCPBind nodeInfo.WsAddr = Conf.WebsocketBind nodeInfo.Weight = Conf.ZookeeperCometWeight data, err := json.Marshal(nodeInfo) if err != nil { log.Error("json.Marshal() error(%v)", err) return conn, err } log.Debug("myzk node:\"%s\" registe data: \"%s\"", fpath, string(data)) if err = myzk.RegisterTemp(conn, fpath, data); err != nil { log.Error("myzk.RegisterTemp() error(%v)", err) return conn, err } // watch and update 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 { log.Error("zk.Connect() error(%v)", err) return nil, err } if err = myzk.Create(conn, Conf.ZookeeperPath); err != nil { log.Error("zk.Create() error(%v)", err) return conn, err } nodeInfo := rpc.MessageNodeInfo{} nodeInfo.Rpc = Conf.RPCBind nodeInfo.Weight = Conf.NodeWeight data, err := json.Marshal(nodeInfo) if err != nil { log.Error("json.Marshal(() error(%v)", err) return conn, err } log.Debug("zk data: \"%s\"", string(data)) // tcp, websocket and rpc bind address store in the zk if err = myzk.RegisterTemp(conn, Conf.ZookeeperPath, data); err != nil { log.Error("zk.RegisterTemp() error(%v)", err) return conn, err } return conn, nil }
func InitZK() (*zk.Conn, error) { conn, err := myzk.Connect(Conf.ZookeeperAddr, Conf.ZookeeperTimeout) if err != nil { log.Error("zk.Connect() error(%v)", err) return nil, err } myrpc.InitComet(conn, Conf.ZookeeperMigratePath, Conf.ZookeeperCometPath, Conf.RPCRetry, Conf.RPCPing) myrpc.InitMessage(conn, Conf.ZookeeperMessagePath, Conf.RPCRetry, Conf.RPCPing) return conn, nil }