grpc

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAddress returned when the address provided is invalid
	ErrInvalidAddress = errors.New("invalid service address")
	// ErrInvalidRegistry returned when the registry provided does not implement regsitry.ServiceRegsitry
	ErrInvalidRegistry = errors.New("registry provided is invalid")
	// ErrTooFewArgs returned when the args provided is less the args required
	ErrTooFewArgs = errors.New("too few arguments. Required 3")
	// ErrTooFewFactoryArgs returned when the args provided is less the args required
	ErrTooFewFactoryArgs = errors.New("too few arguments for the factory. Required 1 address")
	// ErrInvalidDialOptions returned when the dial options provided are not valid
	ErrInvalidDialOptions = errors.New("dial options provided are invalid")
	// ErrInvalidGrpcClient returned when type assertion to GrpcClient fails
	ErrInvalidGrpcClient = errors.New("invalid GrpcClient")
	// ErrInvalidStreamDescription returned when the variable passed is not of grpc.StreamDesc type
	ErrInvalidStreamDescription = errors.New("invalid stream description")
	// ErrInvalidFactoryConn returned when factory conn is invalid
	ErrInvalidFactoryConn = errors.New("invalid factory client connection")
)

Functions

This section is empty.

Types

type ClientOption

type ClientOption func(*Grpc)

ClientOption to pass as arg while creating new service

func WithCloseFunc

func WithCloseFunc(closeFunc pool.CloseFunc) ClientOption

WithCloseFunc passes the callback function to close the gRPC connection in the pool

func WithFactory

func WithFactory(factory pool.Factory) ClientOption

WithFactory defines the client connection creation factory

func WithRegistry

func WithRegistry(registry registry.ServiceRegistry) ClientOption

WithRegistry passes services registry externally

type Grpc

type Grpc struct {
	Registry registry.ServiceRegistry
	sync.RWMutex
	// contains filtered or unexported fields
}

Grpc client that holds the reference to the pool, along with other configuration required to create the pool It holds a reference to the service registry used by the service.

func NewGrpc

func NewGrpc(opts ...ClientOption) *Grpc

NewGrpc creates a new gRPC client

func (*Grpc) Call

func (c *Grpc) Call(
	ctx context.Context,
	sc client.ServiceClient,
	method string,
	req interface{},
	res interface{},
	opts ...client.CallOption,
) error

Call gRPC method

func (*Grpc) Dial

func (c *Grpc) Dial(name string, opts ...client.DialOption) (pool.Connection, error)

Dial creates/gets a connection from the pool using the address from the service registry

func (*Grpc) GetConnFromPool

func (c *Grpc) GetConnFromPool(serviceName string) (pool.Connection, *grpc.ClientConn, error)

Get client conn

func (*Grpc) HasInitializer

func (c *Grpc) HasInitializer() bool

func (*Grpc) Initializer

func (g *Grpc) Initializer() component.Initializer

func (*Grpc) Stream

func (c *Grpc) Stream(
	ctx context.Context,
	sc client.ServiceClient,
	desc interface{},
	method string,
	req interface{},
	opts ...client.CallOption,
) (client.StreamClient, error)

Stream gRPC method

type GrpcStreamClient

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

GrpcStreamClient is the gRPC client that allows streaming. It holds the stream and the connection to the gRPC server.

func (*GrpcStreamClient) CloseAndRecv

func (sc *GrpcStreamClient) CloseAndRecv(res interface{}) error

CloseAndRecv first close the server stream and receives messages on the client stream

func (*GrpcStreamClient) CloseConn

func (sc *GrpcStreamClient) CloseConn() error

CloseConn closes the connection in the pool if the pool is full or adds it back to the pool

func (*GrpcStreamClient) Recv

func (sc *GrpcStreamClient) Recv(res interface{}) error

Recv receive a message from the stream

func (*GrpcStreamClient) Send

func (sc *GrpcStreamClient) Send(req interface{}) error

Send sends a message

type Initializer

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

func NewInitializer

func NewInitializer(g *Grpc) *Initializer

NewInitializer returns a new JetStream Initialiazer

func (*Initializer) AddDependency

func (i *Initializer) AddDependency(dep interface{}) error

AddDependency adds necessary service components as dependencies

func (*Initializer) CanRun

func (i *Initializer) CanRun() bool

CanRun returns true if the component has anything to Run

func (*Initializer) CanStop

func (i *Initializer) CanStop() bool

CanRun returns true if the component has anything to Run

func (*Initializer) Dependencies

func (i *Initializer) Dependencies() []string

Dependencies returns the string names of service components that are required as dependencies for this component

func (*Initializer) Run

func (i *Initializer) Run(ctx context.Context) error

Run start the service component

func (*Initializer) Stop

func (i *Initializer) Stop(ctx context.Context) error

Stop - stops the running

Jump to

Keyboard shortcuts

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