rpc

package
v0.0.0-...-70211e5 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrIllegalHeaderWrite indicates that setting header is illegal because of
	// the stream's state.
	ErrIllegalHeaderWrite = errors.New("transport: the stream is done or WriteHeader was already called")
)

Functions

func Codec

func Codec() grpc.Codec

Codec returns a proxying grpc.Codec with the default protobuf codec as parent.

See CodecWithParent.

func CodecWithParent

func CodecWithParent(fallback grpc.Codec) grpc.Codec

CodecWithParent returns a proxying grpc.Codec with a user provided codec as parent.

This codec is *crucial* to the functioning of the proxy. It allows the proxy server to be oblivious to the schema of the forwarded messages. It basically treats a gRPC message frame as raw bytes. However, if the server handler, or the client caller are not proxy-internal functions it will fall back to trying to decode the message using a fallback codec.

func SetupConnOptions

func SetupConnOptions(opts []nats.Option) []nats.Option

SetupConnOptions default conn opts.

Types

type Client

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

func NewClient

func NewClient(nc NatsConn, svcid string, nid string) *Client

func (*Client) Close

func (p *Client) Close() error

Close gracefully stops a Client

func (*Client) CloseStream

func (p *Client) CloseStream(nid string) bool

func (*Client) Invoke

func (c *Client) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error

Invoke performs a unary RPC and returns after the request is received into reply.

func (*Client) NewStream

func (c *Client) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)

NewStream begins a streaming RPC.

type Frame

type Frame struct {
	Payload []byte
}

type NatsConn

type NatsConn interface {
	Publish(subj string, data []byte) error
	PublishRequest(subj, reply string, data []byte) error
	Request(subj string, data []byte, timeout time.Duration) (*nats.Msg, error)
	ChanSubscribe(subj string, ch chan *nats.Msg) (*nats.Subscription, error)
	SubscribeSync(subj string) (*nats.Subscription, error)
	QueueSubscribe(subj, queue string, cb nats.MsgHandler) (*nats.Subscription, error)
	LastError() error
	Flush() error
}

NatsConn nats connection.

type RawCodec

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

func (*RawCodec) Marshal

func (c *RawCodec) Marshal(v interface{}) ([]byte, error)

func (*RawCodec) String

func (c *RawCodec) String() string

func (*RawCodec) Unmarshal

func (c *RawCodec) Unmarshal(data []byte, v interface{}) error

type Server

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

Server is the interface to gRPC over NATS

func NewServer

func NewServer(nc NatsConn, nid string, options ...ServerOption) *Server

NewServer creates a new Proxy

func (*Server) CloseStream

func (s *Server) CloseStream(nid string) error

func (*Server) GetServiceInfo

func (s *Server) GetServiceInfo() map[string]grpc.ServiceInfo

func (*Server) RegisterService

func (s *Server) RegisterService(sd *grpc.ServiceDesc, ss interface{})

RegisterService is used to register gRPC services

func (*Server) Stop

func (s *Server) Stop()

Stop gracefully stops a Proxy

type ServerOption

type ServerOption interface {
	// contains filtered or unexported methods
}

A ServerOption sets options such as credentials, codec and keepalive parameters, etc.

func ChainStreamInterceptor

func ChainStreamInterceptor(interceptors ...grpc.StreamServerInterceptor) ServerOption

ChainStreamInterceptor returns a ServerOption that specifies the chained interceptor for streaming RPCs. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All stream interceptors added by this method will be chained.

func ChainUnaryInterceptor

func ChainUnaryInterceptor(interceptors ...grpc.UnaryServerInterceptor) ServerOption

ChainUnaryInterceptor returns a ServerOption that specifies the chained interceptor for unary RPCs. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All unary interceptors added by this method will be chained.

Directories

Path Synopsis
Package reflection implements server reflection service.
Package reflection implements server reflection service.

Jump to

Keyboard shortcuts

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