Exemplo n.º 1
0
func InitZK() (*zk.Conn, error) {
	conn, err := myzk.Connect(Conf.ZookeeperAddr, Conf.ZookeeperTimeout)
	if err != nil {
		glog.Errorf("zk.Connect() error(%v)", err)
		return nil, err
	}
	fpath := path.Join(Conf.ZookeeperCometPath, Conf.ZookeeperCometNode)
	if err = myzk.Create(conn, fpath); err != nil {
		glog.Errorf("zk.Create() error(%v)", err)
		return conn, err
	}
	// comet weight with tcp, websocket and rpc bind address store in the zk
	data := fmt.Sprintf("%s;", Conf.ZookeeperCometWeight)
	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, ",")
	glog.V(1).Infof("zk data: \"%s\"", data)
	if err = myzk.RegisterTemp(conn, fpath, data); err != nil {
		glog.Errorf("zk.RegisterTemp() error(%v)", err)
		return conn, err
	}
	rpc.InitMessage(conn, Conf.ZookeeperMessagePath, Conf.RPCRetry, Conf.RPCPing, Conf.KetamaBase)
	return conn, nil
}
Exemplo n.º 2
0
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
	//go watchCometRoot(conn, Conf.ZookeeperCometPath, Conf.KetamaBase)
	rpc.InitMessage(conn, Conf.ZookeeperMessagePath, Conf.RPCRetry, Conf.RPCPing)
	return conn, nil
}
Exemplo n.º 3
0
// 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
}
Exemplo n.º 4
0
// 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 {
		glog.Errorf("zk.Connect() error(%v)", err)
		return nil, err
	}
	if err = myzk.Create(conn, Conf.ZookeeperPath); err != nil {
		glog.Errorf("zk.Create() error(%v)", err)
		return conn, err
	}
	data := strings.Join(Conf.Addr, ",")
	glog.V(1).Infof("zk data: \"%s\"", data)
	// tcp, websocket and rpc bind address store in the zk
	if err = myzk.RegisterTemp(conn, Conf.ZookeeperPath, data); err != nil {
		glog.Errorf("zk.RegisterTemp() error(%v)", err)
		return conn, err
	}
	return conn, nil
}