nrpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package nrpc implements gRPC transport over pubsub like NATS. The interfaces defined in `pubsub` package can be implemented for more pubsub solutions and then used with this module. This package implements the gRPC client and server interfaces of the official google.golang.org/grpc and can be used with grpc code generated with the official generator.

Index

Constants

This section is empty.

Variables

View Source
var (
	MessageType_name = map[int32]string{
		0: "Data",
		1: "Error",
	}
	MessageType_value = map[string]int32{
		"Data":  0,
		"Error": 1,
	}
)

Enum value maps for MessageType.

View Source
var File_message_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type Client

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

Client implements a pub-sub based grpc client.

func NewClient

func NewClient(pub pubsub.Publisher, sub pubsub.Subscriber, opts ...Option) *Client

NewClient creates a new pub-sub based grpc client.

func (*Client) Invoke

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

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

func (*Client) NewStream

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

NewStream begins a streaming RPC.

type Header struct {
	Values []string `protobuf:"bytes,1,rep,name=values,proto3" json:"values,omitempty"`
	// contains filtered or unexported fields
}

func (*Header) Descriptor deprecated

func (*Header) Descriptor() ([]byte, []int)

Deprecated: Use Header.ProtoReflect.Descriptor instead.

func (*Header) GetValues

func (x *Header) GetValues() []string

func (*Header) ProtoMessage

func (*Header) ProtoMessage()

func (*Header) ProtoReflect

func (x *Header) ProtoReflect() protoreflect.Message

func (*Header) Reset

func (x *Header) Reset()

func (*Header) String

func (x *Header) String() string

type Logger

type Logger interface {
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
}

Logger defines the interface for logging.

type Message

type Message struct {

	// Subject of the endpoint.
	Subject string `protobuf:"bytes,1,opt,name=subject,proto3" json:"subject,omitempty"`
	// Type indicates the type of the message.
	Type MessageType `protobuf:"varint,3,opt,name=type,proto3,enum=nrpc.MessageType" json:"type,omitempty"`
	// Data contains the transmitted bytes. This is a protobuf encoded message.
	Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*Message) Descriptor deprecated

func (*Message) Descriptor() ([]byte, []int)

Deprecated: Use Message.ProtoReflect.Descriptor instead.

func (*Message) GetData

func (x *Message) GetData() []byte

func (*Message) GetSubject

func (x *Message) GetSubject() string

func (*Message) GetType

func (x *Message) GetType() MessageType

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) ProtoReflect

func (x *Message) ProtoReflect() protoreflect.Message

func (*Message) Reset

func (x *Message) Reset()

func (*Message) String

func (x *Message) String() string

type MessageType

type MessageType int32
const (
	MessageType_Data  MessageType = 0
	MessageType_Error MessageType = 1
)

func (MessageType) Descriptor

func (MessageType) Enum

func (x MessageType) Enum() *MessageType

func (MessageType) EnumDescriptor deprecated

func (MessageType) EnumDescriptor() ([]byte, []int)

Deprecated: Use MessageType.Descriptor instead.

func (MessageType) Number

func (x MessageType) Number() protoreflect.EnumNumber

func (MessageType) String

func (x MessageType) String() string

func (MessageType) Type

type Option

type Option func(opt *options)

Option defines an option for configuring the server.

func StatsHandler added in v0.1.0

func StatsHandler(handler stats.Handler) Option

StatsHandler returns a ServerOption that sets the StatsHandler for the server. It can be used to add tracing, metrics, etc.

func StreamInterceptor added in v0.0.4

func StreamInterceptor(i grpc.StreamServerInterceptor) Option

StreamInterceptor returns a ServerOption that sets the StreamServerInterceptor for the server. Only one stream interceptor can be installed.

func UnaryInterceptor added in v0.0.4

func UnaryInterceptor(i grpc.UnaryServerInterceptor) Option

UnaryInterceptor returns a ServerOption that sets the UnaryServerInterceptor for the server. Only one unary interceptor can be installed. The construction of multiple interceptors (e.g., chaining) can be implemented at the caller.

func WithLogger

func WithLogger(log Logger) Option

WithLogger sets the logger for the client or server.

type Request

type Request struct {

	// Headers contain the custom metadata of the request.
	Header map[string]*Header `` /* 153-byte string literal not displayed */
	// Data contains the transmitted bytes. This is a protobuf encoded message.
	Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// EOS indicates the end of client side stream.
	Eos bool `protobuf:"varint,3,opt,name=eos,proto3" json:"eos,omitempty"`
	// The subject the server should open the stream for.
	ReqSubject string `protobuf:"bytes,4,opt,name=req_subject,json=reqSubject,proto3" json:"req_subject,omitempty"`
	// The subject the client has opened the stream for.
	RespSubject string `protobuf:"bytes,5,opt,name=resp_subject,json=respSubject,proto3" json:"resp_subject,omitempty"`
	// Timeout is a duration in nanoseconds the request is allowed to take.
	// Set to 0 for no timeout.
	Timeout int64 `protobuf:"varint,6,opt,name=timeout,proto3" json:"timeout,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

func (*Request) Descriptor() ([]byte, []int)

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetData

func (x *Request) GetData() []byte

func (*Request) GetEos

func (x *Request) GetEos() bool

func (*Request) GetHeader

func (x *Request) GetHeader() map[string]*Header

func (*Request) GetReqSubject

func (x *Request) GetReqSubject() string

func (*Request) GetRespSubject

func (x *Request) GetRespSubject() string

func (*Request) GetTimeout

func (x *Request) GetTimeout() int64

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {

	// Headers contain the custom metadata of the response.
	Header map[string]*Header `` /* 153-byte string literal not displayed */
	// HeaderOnly reports whether the response is a SendHeader and doesn't contain data.
	HeaderOnly bool `protobuf:"varint,5,opt,name=header_only,json=headerOnly,proto3" json:"header_only,omitempty"`
	// Data contains the transmitted bytes. This is a protobuf encoded message.
	Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	// EOS indicates the end of client side stream.
	Eos bool `protobuf:"varint,3,opt,name=eos,proto3" json:"eos,omitempty"`
	// Trailer contain custom trailer of the response.
	Trailer map[string]*Header `` /* 155-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

func (*Response) Descriptor() ([]byte, []int)

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetData

func (x *Response) GetData() []byte

func (*Response) GetEos

func (x *Response) GetEos() bool

func (*Response) GetHeader

func (x *Response) GetHeader() map[string]*Header

func (*Response) GetHeaderOnly

func (x *Response) GetHeaderOnly() bool

func (*Response) GetTrailer

func (x *Response) GetTrailer() map[string]*Header

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type Server

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

Server implements the grpc.ServiceRegistrar interface.

func NewServer

func NewServer(pub pubsub.Publisher, sub pubsub.Subscriber, opts ...Option) *Server

NewServer creates a new pub-sub based grpc server.

func (*Server) GetServiceInfo added in v0.0.4

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

GetServiceInfo implements the grpc.ServiceInfoProvider interface.

func (*Server) Listen added in v0.0.3

func (s *Server) Listen(ctx context.Context) error

Listen starts the server by subscribing to the registered endpoints and blocks until closed or an error occurs.

func (*Server) RegisterService

func (s *Server) RegisterService(desc *grpc.ServiceDesc, impl interface{})

RegisterService implements the grpc.ServiceRegistrar interface.

func (*Server) Run added in v0.0.3

func (s *Server) Run(ctx context.Context) error

Run starts the server by subscribing to the registered endpoints.

func (*Server) Stop added in v0.0.3

func (s *Server) Stop()

Stop signals the Service to shut down. Stopping is done when the Listen function returns.

type StandardLogger

type StandardLogger struct{}

StandardLogger implements the Logger interface using the standard library logger.

func (StandardLogger) Error

func (d StandardLogger) Error(args ...interface{})

Error implements the Logger interface.

func (StandardLogger) Errorf

func (d StandardLogger) Errorf(format string, args ...interface{})

Errorf implements the Logger interface.

func (StandardLogger) Info

func (d StandardLogger) Info(args ...interface{})

Info implements the Logger interface

func (StandardLogger) Infof

func (d StandardLogger) Infof(format string, args ...interface{})

Infof implements the Logger interface.

Directories

Path Synopsis
Package pubsub defines the Publisher and Subscriber interfaces.
Package pubsub defines the Publisher and Subscriber interfaces.
nats
Package nats implements the pub/sub interfaces for NATS.
Package nats implements the pub/sub interfaces for NATS.
Package testproto contains the generated testproto grpc code.
Package testproto contains the generated testproto grpc code.
testclient
Package testclient creates a new client for the testproto service used in tests.
Package testclient creates a new client for the testproto service used in tests.
testserver
Package testserver implements the testproto service used in tests.
Package testserver implements the testproto service used in tests.

Jump to

Keyboard shortcuts

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