Documentation ¶
Overview ¶
Package grpc_connection_pool provides the ability to create connection pool for gRPC.
Here is example to create connection pool:
// Create Options object options := &pool.Options{ InitCap: 8, MaxCap: 16, DialTimeout: time.Second * 20, } // Create connection pool with options pool, err := grpc_connection_pool.NewGRPCPool("localhost:8888", options, grpc.WithInsecure()) if err != nil { log.Println(err) return } // Get a available gRPC client client := pool.Get()
Index ¶
- Variables
- type Connection
- type GRPCPool
- func (pool *GRPCPool) Get() (*grpc.ClientConn, error)
- func (pool *GRPCPool) GetStream(name string, fn StreamHandler) error
- func (pool *GRPCPool) GetStreamInitializer(name string) StreamInitializer
- func (pool *GRPCPool) Pop() (*grpc.ClientConn, error)
- func (pool *GRPCPool) Push(connection *grpc.ClientConn) error
- func (pool *GRPCPool) SetStreamInitializer(name string, initializer StreamInitializer)
- type Options
- type StreamHandler
- type StreamInitializer
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrExceeded = errors.New("Maximum number of connections exceeded")
ErrExceeded is the error when maximum number of connections exceeded
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(pool *GRPCPool, c *grpc.ClientConn) *Connection
func (*Connection) GetStream ¶ added in v0.4.0
func (connection *Connection) GetStream(name string, fn StreamHandler) error
type GRPCPool ¶
type GRPCPool struct {
// contains filtered or unexported fields
}
func NewGRPCPool ¶
NewGRPCPool creates a new connection pool.
func (*GRPCPool) Get ¶
func (pool *GRPCPool) Get() (*grpc.ClientConn, error)
Get will returns a available gRPC client.
func (*GRPCPool) GetStream ¶ added in v0.4.0
func (pool *GRPCPool) GetStream(name string, fn StreamHandler) error
func (*GRPCPool) GetStreamInitializer ¶ added in v0.4.0
func (pool *GRPCPool) GetStreamInitializer(name string) StreamInitializer
func (*GRPCPool) Pop ¶
func (pool *GRPCPool) Pop() (*grpc.ClientConn, error)
Pop will return a availabe gRPC client and the gRPC client will not be reused before return client to the pool.
func (*GRPCPool) Push ¶
func (pool *GRPCPool) Push(connection *grpc.ClientConn) error
Push will put gRPC client to the pool.
func (*GRPCPool) SetStreamInitializer ¶ added in v0.4.0
func (pool *GRPCPool) SetStreamInitializer(name string, initializer StreamInitializer)
type Options ¶
Options represent all of the available options when creating a connection pool with NewGRPCPool.
type StreamHandler ¶ added in v0.5.0
type StreamHandler func(interface{}) error
type StreamInitializer ¶ added in v0.4.0
type StreamInitializer func(*grpc.ClientConn) (interface{}, error)
Click to show internal directories.
Click to hide internal directories.