grpc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Server ConnectionType = iota
	Client

	Idle ConnState = iota
	Connecting
	Ready
	TransientFailure
	ShutDown
)

Variables

View Source
var (
	// DefaultConnectionType [Client], library initiate the gRPC client connection
	DefaultConnectionType = Client

	// DefaultInsecureState : the authentication state of gRPC connection
	DefaultInsecureState = true

	// DefaultServerPort : the server port of gRPC connection
	DefaultServerPort = "50051"

	// DefaultPoolSize : the connection pool size to create gRPC connections
	DefaultPoolSize uint64 = 60
)

Functions

This section is empty.

Types

type ConnState

type ConnState connectivity.State

ConnState : Connectivity State of gRPC connection [Idle,Connecting,Ready,TransientFailure,Shutdown]

type ConnectionType

type ConnectionType int

ConnectionType gRPC[client:server]

type GRPC

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

GRPC struct defines the Connection objects for both client and server.

connectionType: The gRPC connection library can be used as client and server connection. The connectiontype
can provide provide conn options to the user.

server:  The GRPC server connection instance gets stored in this field.

serverAddress: The gRPC server address that listens to certain ports.

serverOptions: There are several gRPC serverOptions can be set as a server configuration.

pool: The connection pool will create multiple gRPC client connections by replicating the base connection
instance into a reusable connection pool.

log: The gRPC log will show the internal connection lifecycle that will be useful to debug the connection flow.

func NewGRPCConnection

func NewGRPCConnection(opts ...Options) (*GRPC, error)

NewGRPCConnection will instantiate the GRPC object and will configure the field objects with the several Options parameters. The connection pool gets instantiated with the serverAddress set by the Options.WithAddress.

func (*GRPC) GetConn

func (g *GRPC) GetConn() (*grpc.ClientConn, error)

GetConn will provide the gRPC client connection instance by querying to the connection pool that retrieves the gRPC client connections via performing the batch processing.

func (*GRPC) ListenAndServe

func (g *GRPC) ListenAndServe() error

ListenAndServe will start listening to the specific serverPort with the "tcp" network type. After the server listener socket is opened, the initial Ping request gets registered that can be used by any gRPC clients to sent Ping-Pong request to check the client-server gRPC connection health status.

func (*GRPC) TestGetConn

func (g *GRPC) TestGetConn() (*grpc.ClientConn, error)

TestGetConn to test the recurrent connection pool iteration to get the gRPC connection instances.

type Options

type Options func(*GRPC)

func WithAddress

func WithAddress(address string) Options

func WithConnectionType

func WithConnectionType(connectionType ConnectionType) Options

func WithPort

func WithPort(port string) Options

func WithServerOptions

func WithServerOptions(serverOption ...grpc.ServerOption) Options

Jump to

Keyboard shortcuts

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