pool

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPoolFull 池满
	ErrPoolFull = errors.New("grpc pool closing a ClientConn into a full pool")
	// ErrPoolTimeout 超时
	ErrPoolTimeout = errors.New("grpc pool get client timeout")
	// ErrPoolClosed 已关闭
	ErrPoolClosed = errors.New("grpc pool is closed")
	// ErrPoolCapacity 错误的容量设置
	ErrPoolCapacity = errors.New("grpc pool wrong capacity")
)

Functions

This section is empty.

Types

type ClientConn

type ClientConn struct {
	*grpc.ClientConn
	// contains filtered or unexported fields
}

ClientConn grpc.ClientConn 的包装

func (*ClientConn) Put

func (c *ClientConn) Put() error

Put 放回池中

func (*ClientConn) Unhealthy

func (c *ClientConn) Unhealthy()

Unhealthy 将连接设置为不健康状态

type GRPCConnFactory

type GRPCConnFactory func() (*grpc.ClientConn, error)

GRPCConnFactory 用于提供创建grpc.ClientConn

type GRPCPool

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

GRPCPool grpc client pool

func NewGRPCPool

func NewGRPCPool(factory GRPCConnFactory, initNum, capacity int, idleTimeout time.Duration) (*GRPCPool, error)

NewGRPCPool 新建 grpc 连接池

func (*GRPCPool) Available

func (p *GRPCPool) Available() int

Available 返回可用的client数量

func (*GRPCPool) Capacity

func (p *GRPCPool) Capacity() int

Capacity 返回池的总容量

func (*GRPCPool) Close

func (p *GRPCPool) Close()

Close 关闭并清理pool

func (*GRPCPool) Get

func (p *GRPCPool) Get(ctx context.Context) (*ClientConn, error)

Get 从池中获取一个client conn,传入WithTimeout的context 可以在 #池满# 的时候获得超时信号。

Jump to

Keyboard shortcuts

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