Example #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
}
Example #2
0
func (self *NsqdRpcClient) Reconnect() error {
	self.Lock()
	if self.c != nil {
		self.c.Stop()
	}
	if self.grpcConn != nil {
		self.grpcConn.Close()
	}
	self.c = gorpc.NewTCPClient(self.remote)
	self.c.RequestTimeout = self.timeout
	self.c.DisableCompression = true
	self.dc = self.d.NewServiceClient("NsqdCoordRpcServer", self.c)
	self.c.Start()

	//ip, port, _ := net.SplitHostPort(self.remote)
	//portNum, _ := strconv.Atoi(port)
	//grpcAddr := ip + ":" + strconv.Itoa(portNum+1)
	//grpcConn, err := grpc.Dial(grpcAddr, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(self.timeout))
	//if err != nil {
	//	coordLog.Warningf("failed to connect to grpc server %v: %v", grpcAddr, err)
	//	self.grpcConn = nil
	//	self.grpcClient = nil
	//} else {
	//	self.grpcConn = grpcConn
	//	self.grpcClient = pb.NewNsqdCoordRpcV2Client(grpcConn)
	//}
	coordLog.Infof("reconnected to rpc server %v", self.remote)

	self.Unlock()
	return nil
}
Example #3
0
func (self *NsqLookupRpcClient) Reconnect() error {
	self.Lock()
	if self.c != nil {
		self.c.Stop()
	}
	self.c = gorpc.NewTCPClient(self.remote)
	self.c.RequestTimeout = self.timeout
	self.c.DisableCompression = true
	self.c.Start()
	self.dc = self.d.NewServiceClient("NsqLookupCoordRpcServer", self.c)
	self.Unlock()
	return nil
}
Example #4
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
}