Documentation ¶
Overview ¶
Package grpcpool provides a pool of grpc clients
Index ¶
- Variables
- func GetConfigConn(serviceName string, operationID string) *grpc.ClientConn
- func GetDefaultConn(schema, etcdaddr, serviceName string, operationID string) *grpc.ClientConn
- func GetDefaultGatewayConn4Unique(schema, etcdaddr, operationID string) []*grpc.ClientConn
- func GetDefaultGatewayConn4UniqueFromcfg(operationID string) []*grpc.ClientConn
- func GetGrpcConn(schema, etcdaddr, servicename string) *grpc.ClientConn
- func GetPrefix(schema, serviceName string) string
- func GetPrefix4Unique(schema, serviceName string) string
- func GetTarget(schema, myHost string, myPort int, serviceName string) string
- func GetconnFactory(schema, etcdaddr, servicename string) (*grpc.ClientConn, error)
- func RegisterConf()
- func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int) error
- func RegisterEtcd4Unique(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int) error
- func UnRegisterEtcd()
- type ClientConn
- type Factory
- type FactoryWithContext
- type Pool
- type RegEtcd
- type Resolver
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is the error when the client pool is closed ErrClosed = errors.New("grpc pool: client pool is closed") // ErrTimeout is the error when the client pool timed out ErrTimeout = errors.New("grpc pool: client pool timed out") // ErrAlreadyClosed is the error when the client conn was already closed ErrAlreadyClosed = errors.New("grpc pool: the connection was already closed") // ErrFullPool is the error when the pool is already full ErrFullPool = errors.New("grpc pool: closing a ClientConn into a full pool") )
var Conn4UniqueList []*grpc.ClientConn
var Conn4UniqueListMtx sync.RWMutex
var IsUpdateStart bool
var IsUpdateStartMtx sync.RWMutex
Functions ¶
func GetConfigConn ¶
func GetConfigConn(serviceName string, operationID string) *grpc.ClientConn
func GetDefaultConn ¶
func GetDefaultConn(schema, etcdaddr, serviceName string, operationID string) *grpc.ClientConn
func GetDefaultGatewayConn4Unique ¶
func GetDefaultGatewayConn4Unique(schema, etcdaddr, operationID string) []*grpc.ClientConn
func GetDefaultGatewayConn4UniqueFromcfg ¶
func GetDefaultGatewayConn4UniqueFromcfg(operationID string) []*grpc.ClientConn
func GetGrpcConn ¶
func GetGrpcConn(schema, etcdaddr, servicename string) *grpc.ClientConn
func GetconnFactory ¶
func GetconnFactory(schema, etcdaddr, servicename string) (*grpc.ClientConn, error)
func RegisterConf ¶
func RegisterConf()
func RegisterEtcd ¶
etcdAddr separated by commas
func RegisterEtcd4Unique ¶
func RegisterEtcd4Unique(schema, etcdAddr, myHost string, myPort int, serviceName string, ttl int) error
"%s:///%s/" -> "%s:///%s:ip:port"
func UnRegisterEtcd ¶
func UnRegisterEtcd()
Types ¶
type ClientConn ¶
type ClientConn struct { *grpc.ClientConn // contains filtered or unexported fields }
ClientConn is the wrapper for a grpc client conn
func GetConnPool ¶
func GetConnPool(schema, etcdaddr, servicename string) (*ClientConn, error)
func (*ClientConn) Close ¶
func (c *ClientConn) Close() error
Close returns a ClientConn to the pool. It is safe to call multiple time, but will return an error after first time
func (*ClientConn) Unhealthy ¶
func (c *ClientConn) Unhealthy()
Unhealthy marks the client conn as unhealthy, so that the connection gets reset when closed
type Factory ¶
type Factory func(schema, etcdaddr, servicename string) (*grpc.ClientConn, error)
Factory is a function type creating a grpc client
type FactoryWithContext ¶
type FactoryWithContext func(context.Context) (*grpc.ClientConn, error)
FactoryWithContext is a function type creating a grpc client that accepts the context parameter that could be passed from Get or NewWithContext method.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is the grpc client pool
func New ¶
func New(factory Factory, schema, etcdaddr, servicename string, init, capacity int, idleTimeout time.Duration, maxLifeDuration ...time.Duration) (*Pool, error)
New creates a new clients pool with the given initial and maximum capacity, and the timeout for the idle clients. Returns an error if the initial clients could not be created
func NewWithContext ¶
func NewWithContext(ctx context.Context, factory FactoryWithContext, init, capacity int, idleTimeout time.Duration, maxLifeDuration ...time.Duration) (*Pool, error)
NewWithContext creates a new clients pool with the given initial and maximum capacity, and the timeout for the idle clients. The context parameter would be passed to the factory method during initialization. Returns an error if the initial clients could not be created.
func (*Pool) Close ¶
func (p *Pool) Close()
Close empties the pool calling Close on all its clients. You can call Close while there are outstanding clients. The pool channel is then closed, and Get will not be allowed anymore
func (*Pool) Get ¶
func (p *Pool) Get(ctx context.Context) (*ClientConn, error)
Get will return the next available client. If capacity has not been reached, it will create a new one using the factory. Otherwise, it will wait till the next client becomes available or a timeout. A timeout of 0 is an indefinite wait
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
func NewResolver ¶
func (*Resolver) Build ¶
func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error)
func (*Resolver) ResolveNow ¶
func (r1 *Resolver) ResolveNow(rn resolver.ResolveNowOptions)