Пример #1
0
func NewNsqdRpcClient(addr string, timeout time.Duration) (*NsqdRpcClient, error) {
	c := gorpc.NewTCPClient(addr)
	c.RequestTimeout = timeout
	c.DisableCompression = true
	c.Start()
	d := gorpc.NewDispatcher()
	d.AddService("NsqdCoordRpcServer", &NsqdCoordRpcServer{})
	//ip, port, _ := net.SplitHostPort(addr)
	//portNum, _ := strconv.Atoi(port)
	//grpcAddr := ip + ":" + strconv.Itoa(portNum+1)
	//grpcConn, err := grpc.Dial(grpcAddr, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(timeout))
	var grpcClient pb.NsqdCoordRpcV2Client
	//if err != nil {
	//	coordLog.Warningf("failed to connect to grpc server %v: %v", grpcAddr, err)
	//	grpcClient = nil
	//	grpcConn = nil
	//} else {
	//	grpcClient = pb.NewNsqdCoordRpcV2Client(grpcConn)
	//}
	coordLog.Infof("connected to rpc server %v", addr)

	return &NsqdRpcClient{
		remote:     addr,
		timeout:    timeout,
		d:          d,
		c:          c,
		dc:         d.NewServiceClient("NsqdCoordRpcServer", c),
		grpcClient: grpcClient,
		grpcConn:   nil,
	}, nil
}
Пример #2
0
func NewNsqdCoordRpcServer(coord *NsqdCoordinator, rootPath string) *NsqdCoordRpcServer {
	return &NsqdCoordRpcServer{
		nsqdCoord:     coord,
		rpcDispatcher: gorpc.NewDispatcher(),
		dataRootPath:  rootPath,
	}
}
Пример #3
0
func NewNsqLookupRpcClient(addr string, timeout time.Duration) (INsqlookupRemoteProxy, error) {
	c := gorpc.NewTCPClient(addr)
	c.RequestTimeout = timeout
	c.DisableCompression = true
	c.Start()
	d := gorpc.NewDispatcher()
	d.AddService("NsqLookupCoordRpcServer", &NsqLookupCoordRpcServer{})

	return &NsqLookupRpcClient{
		remote:  addr,
		timeout: timeout,
		d:       d,
		c:       c,
		dc:      d.NewServiceClient("NsqLookupCoordRpcServer", c),
	}, nil
}