Beispiel #1
0
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
}
Beispiel #2
0
func InitZK() (*zk.Conn, error) {
	conn, err := myzk.Connect(app.Conf.ZookeeperAddr, app.Conf.ZookeeperTimeout)
	if err != nil {
		logger.Errorf("zk.Connect() error(%v)", err)
		return nil, err
	}
	myrpc.InitComet(conn, app.Conf.ZookeeperCometPath, app.Conf.RPCRetry, app.Conf.RPCPing)
	myrpc.InitMessage(conn, app.Conf.ZookeeperMessagePath, app.Conf.RPCRetry, app.Conf.RPCPing)
	return conn, nil
}
Beispiel #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 {
		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
}