client

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientConnectClosed = errors.New("client connect is closed")
	ErrNoServer            = errors.New("no service can be invoked")
)
View Source
var (
	ErrTooFewParam       = errors.New("zrpc-cli: too few parameters")
	ErrTooFewReturn      = errors.New("zrpc-cli: too few return values")
	ErrInvalidParamType  = errors.New("zrpc-cli: the first param must be Context")
	ErrInvalidResultType = errors.New("zrpc-cli: the last return value must be error")
)
View Source
var (
	// ErrClosed client is closed
	ErrClosed = errors.New("zrpc-cli: client is closed")
)
View Source
var (
	// ErrPoolTimeout timed out waiting to get a client from the client pool.
	ErrPoolTimeout = errors.New("zrpc-cli: connection pool timeout")
)

Functions

This section is empty.

Types

type CliPool

type CliPool struct {
	// contains filtered or unexported fields
}

func NewDirectPool

func NewDirectPool(server ServerInfo, opt ...Option) (*CliPool, error)

NewDirectPool 连接池(只适用于单节点)

func (*CliPool) Close

func (pool *CliPool) Close() error

func (*CliPool) Decorator

func (pool *CliPool) Decorator(name string, i interface{}, retry int) error

Decorator 将 server proxy 装饰为可调用 server

func (*CliPool) GetSerivce

func (pool *CliPool) GetSerivce(name string) (interface{}, bool)

GetSerivce 获取已注册 rpc 服务实例以供使用

func (*CliPool) IdleLen

func (pool *CliPool) IdleLen() int

func (*CliPool) Len

func (pool *CliPool) Len() int

type Option

type Option func(opt *options)

func WithMinIdleCount

func WithMinIdleCount(n int) Option

func WithPoolSize

func WithPoolSize(size int) Option

type ServerInfo

type ServerInfo struct {
	ServerName    string
	NodeID        string
	LocalEndpoint zrpc.Endpoint // 本地 endpoint
	StateEndpoint zrpc.Endpoint // 状态 endpoint
}

type ZrpcClient

type ZrpcClient struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(discover zrpc.ServiceDiscover) (*ZrpcClient, error)

NewClient 使用注册/发现中心创建客户端

func NewDirectClient

func NewDirectClient(server ServerInfo) (*ZrpcClient, error)

NewDirectClient 根据 rpc 服务地址连接的客户端(只适用于单节点服务)

func (*ZrpcClient) Close

func (cli *ZrpcClient) Close() error

func (*ZrpcClient) Decorator

func (cli *ZrpcClient) Decorator(name string, i interface{}, retry int) error

Decorator 将 server proxy 装饰为可调用 server

func (*ZrpcClient) GetSerivce

func (cli *ZrpcClient) GetSerivce(name string) (interface{}, bool)

GetSerivce 获取已注册 rpc 服务实例以供使用

func (*ZrpcClient) Identity

func (cli *ZrpcClient) Identity() string

func (*ZrpcClient) Send

func (cli *ZrpcClient) Send(p *zrpc.Pack) (string, error)

Send 发送 pack

func (*ZrpcClient) SpecifySend

func (cli *ZrpcClient) SpecifySend(id string, p *zrpc.Pack) error

SpecifySend 向指定服务节点发送 pack

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL