grpcpool

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

grpcpool

PkgGoDev

grpc pool

Documentation

Index

Constants

View Source
const (
	// OPENED represents that the pool is opened.
	OPENED = iota

	// CLOSED represents that the pool is closed.
	CLOSED
)

Variables

View Source
var (
	// ErrPoolClosed pool 连接已关闭
	ErrPoolClosed = errors.New("grpc pool has closed")

	// ErrConnClosed grpc 连接已关闭
	ErrConnClosed = errors.New("the grpc connection has closed")

	// ErrPoolOverload 连接池资源已满载
	ErrPoolOverload = errors.New("pool overload")
)

Functions

This section is empty.

Types

type Builder

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

Builder 创建conn的构造函数

type Logger

type Logger interface {
	// Printf must have the same semantics as log.Printf.
	Printf(format string, args ...interface{})
}

Logger is used for logging formatted messages.

type LogicConn

type LogicConn interface {
	Conn() grpc.ClientConnInterface
	// contains filtered or unexported methods
}

LogicConn grpc 逻辑连接接口

type Option

type Option func(*option)

Option .

func WithCleanIntervalTime

func WithCleanIntervalTime(t time.Duration) Option

WithCleanIntervalTime set interval time to clean up idle connections or create new tcp connection

func WithClientIdleTimeout

func WithClientIdleTimeout(t time.Duration) Option

WithClientIdleTimeout .

func WithDebug

func WithDebug() Option

WithDebug .

func WithGrpcPoolSize

func WithGrpcPoolSize(size int) Option

WithGrpcPoolSize returns a Option which sets the value for pool size

func WithLogger

func WithLogger(logger Logger) Option

WithLogger returns a Option which sets the value for pool logger

func WithMaxIdle

func WithMaxIdle(num int) Option

WithMaxIdle set number of idle connections in the pool.

func WithMaxStreamsClient

func WithMaxStreamsClient(num int) Option

WithMaxStreamsClient returns a Option which set the value for http2 client maxConcurrentStreams

func WithNonblocking

func WithNonblocking() Option

WithNonblocking returns a Option which Pool.Get can never be blocked. ErrPoolOverload will be returned when Pool is exhausted.

type Pool

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

Pool grpc 连接池

func NewPool

func NewPool(builder Builder, opts ...Option) (pool *Pool, err error)

NewPool create a grpc pool

func (*Pool) Close

func (p *Pool) Close()

Close close pool

func (*Pool) Get

func (p *Pool) Get() (logicconn LogicConn, err error)

Get get a grpc logic connection

func (*Pool) Lock

func (*Pool) Lock()

func (*Pool) Put

func (p *Pool) Put(lc LogicConn)

Put release grpc logic connection

func (*Pool) UnLock

func (*Pool) UnLock()

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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