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 ¶
- Variables
- type Client
- type Header
- type Logger
- type Message
- func (*Message) Descriptor() ([]byte, []int)deprecated
- func (x *Message) GetData() []byte
- func (x *Message) GetSubject() string
- func (x *Message) GetType() MessageType
- func (*Message) ProtoMessage()
- func (x *Message) ProtoReflect() protoreflect.Message
- func (x *Message) Reset()
- func (x *Message) String() string
- type MessageType
- func (MessageType) Descriptor() protoreflect.EnumDescriptor
- func (x MessageType) Enum() *MessageType
- func (MessageType) EnumDescriptor() ([]byte, []int)deprecated
- func (x MessageType) Number() protoreflect.EnumNumber
- func (x MessageType) String() string
- func (MessageType) Type() protoreflect.EnumType
- type Option
- type Request
- func (*Request) Descriptor() ([]byte, []int)deprecated
- func (x *Request) GetData() []byte
- func (x *Request) GetEos() bool
- func (x *Request) GetHeader() map[string]*Header
- func (x *Request) GetReqSubject() string
- func (x *Request) GetRespSubject() string
- func (x *Request) GetTimeout() int64
- func (*Request) ProtoMessage()
- func (x *Request) ProtoReflect() protoreflect.Message
- func (x *Request) Reset()
- func (x *Request) String() string
- type Response
- func (*Response) Descriptor() ([]byte, []int)deprecated
- func (x *Response) GetData() []byte
- func (x *Response) GetEos() bool
- func (x *Response) GetHeader() map[string]*Header
- func (x *Response) GetHeaderOnly() bool
- func (x *Response) GetTrailer() map[string]*Header
- func (*Response) ProtoMessage()
- func (x *Response) ProtoReflect() protoreflect.Message
- func (x *Response) Reset()
- func (x *Response) String() string
- type Server
- type StandardLogger
Constants ¶
This section is empty.
Variables ¶
var ( MessageType_name = map[int32]string{ 0: "Data", 1: "Error", } MessageType_value = map[string]int32{ "Data": 0, "Error": 1, } )
Enum value maps for MessageType.
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 (*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 ¶
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) ProtoMessage ¶
func (*Header) ProtoMessage()
func (*Header) ProtoReflect ¶
func (x *Header) ProtoReflect() protoreflect.Message
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) GetSubject ¶
func (*Message) GetType ¶
func (x *Message) GetType() MessageType
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
func (*Message) ProtoReflect ¶
func (x *Message) ProtoReflect() protoreflect.Message
type MessageType ¶
type MessageType int32
const ( MessageType_Data MessageType = 0 MessageType_Error MessageType = 1 )
func (MessageType) Descriptor ¶
func (MessageType) Descriptor() protoreflect.EnumDescriptor
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 ¶
func (MessageType) Type() protoreflect.EnumType
type Option ¶
type Option func(opt *options)
Option defines an option for configuring the server.
func StatsHandler ¶ added in v0.1.0
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 ¶
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) GetReqSubject ¶
func (*Request) GetRespSubject ¶
func (*Request) GetTimeout ¶
func (*Request) ProtoMessage ¶
func (*Request) ProtoMessage()
func (*Request) ProtoReflect ¶
func (x *Request) ProtoReflect() protoreflect.Message
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) GetHeaderOnly ¶
func (*Response) GetTrailer ¶
func (*Response) ProtoMessage ¶
func (*Response) ProtoMessage()
func (*Response) ProtoReflect ¶
func (x *Response) ProtoReflect() protoreflect.Message
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server implements the grpc.ServiceRegistrar interface.
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
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.
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.
Source Files
¶
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. |