grpc_connection_pool

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: MIT Imports: 8 Imported by: 2

README

grpc-connection-pool

GoDoc

Package grpc_connection_pool provides the ability to create connection pool for gRPC.

License

Licensed under the MIT License

Authors

Copyright(c) 2020 Fred Chien cfsghost@gmail.com

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

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

View Source
var ErrUnavailable = errors.New("No available connection")

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

func NewGRPCPool(host string, options *Options, dialOptions ...grpc.DialOption) (*GRPCPool, error)

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

type Options struct {
	InitCap     int
	MaxCap      int
	DialTimeout time.Duration
}

Options represent all of the available options when creating a connection pool with NewGRPCPool.

func NewOptions

func NewOptions() *Options

NewOptions creates a Options object.

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)

Jump to

Keyboard shortcuts

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