Documentation ¶
Index ¶
- Variables
- func Call(req proto.Message, rep proto.Message, nc NatsConn, subject string, ...) error
- func Marshal(encoding string, msg proto.Message) ([]byte, error)
- func MarshalErrorResponse(encoding string, repErr *Error) ([]byte, error)
- func ParseSubject(packageSubject string, packageParamsCount int, serviceSubject string, ...) (packageParams []string, serviceParams []string, name string, tail []string, ...)
- func ParseSubjectTail(methodParamsCount int, tail []string) (methodParams []string, encoding string, err error)
- func Publish(resp proto.Message, withError *Error, nc NatsConn, subject string, ...) error
- func Unmarshal(encoding string, data []byte, msg proto.Message) error
- func UnmarshalResponse(encoding string, data []byte, msg proto.Message) error
- type ContextKey
- type Error
- func (*Error) Descriptor() ([]byte, []int)deprecated
- func (e *Error) Error() string
- func (x *Error) GetMessage() string
- func (x *Error) GetMsgCount() uint32
- func (x *Error) GetType() Error_Type
- func (*Error) ProtoMessage()
- func (x *Error) ProtoReflect() protoreflect.Message
- func (x *Error) Reset()
- func (x *Error) String() string
- type Error_Type
- type Heartbeat
- type KeepStreamAlive
- type NatsConn
- type NoReply
- type NoRequest
- type ReplyInboxMaker
- type Request
- func (r *Request) Elapsed() time.Duration
- func (r *Request) EnableStreamedReply()
- func (r *Request) PackageParam(key string) string
- func (r *Request) Run() (msg proto.Message, replyError *Error)
- func (r *Request) RunAndReply()
- func (r *Request) SendErrorTooBusy(msg string) error
- func (r *Request) SendReply(resp proto.Message, withError *Error) error
- func (r *Request) SendStreamReply(msg proto.Message)
- func (r *Request) ServiceParam(key string) string
- func (r *Request) SetPackageParam(key, value string)
- func (r *Request) SetServiceParam(key, value string)
- func (r *Request) StreamedReply() bool
- type StreamCallSubscription
- type SubjectRule
- func (SubjectRule) Descriptor() protoreflect.EnumDescriptor
- func (x SubjectRule) Enum() *SubjectRule
- func (SubjectRule) EnumDescriptor() ([]byte, []int)deprecated
- func (x SubjectRule) Number() protoreflect.EnumNumber
- func (x SubjectRule) String() string
- func (SubjectRule) Type() protoreflect.EnumType
- type Void
- type WorkerPool
Constants ¶
This section is empty.
Variables ¶
var ( SubjectRule_name = map[int32]string{ 0: "COPY", 1: "TOLOWER", } SubjectRule_value = map[string]int32{ "COPY": 0, "TOLOWER": 1, } )
Enum value maps for SubjectRule.
var ( Error_Type_name = map[int32]string{ 0: "CLIENT", 1: "SERVER", 3: "EOS", 4: "SERVERTOOBUSY", } Error_Type_value = map[string]int32{ "CLIENT": 0, "SERVER": 1, "EOS": 3, "SERVERTOOBUSY": 4, } )
Enum value maps for Error_Type.
var ( // A custom subject prefix to use instead of the package name // // optional string packageSubject = 50000; E_PackageSubject = &file_nrpc_proto_extTypes[0] // Parameters included in the subject at the package level // // repeated string packageSubjectParams = 50001; E_PackageSubjectParams = &file_nrpc_proto_extTypes[1] // Default rule to build a service subject from the service name // // optional nrpc.SubjectRule serviceSubjectRule = 50002; E_ServiceSubjectRule = &file_nrpc_proto_extTypes[2] // Default rule to build a method subject from its name // // optional nrpc.SubjectRule methodSubjectRule = 50003; E_MethodSubjectRule = &file_nrpc_proto_extTypes[3] )
Extension fields to descriptor.FileOptions.
var ( // A custom subject token to use instead of (service name + serviceSubjectRule) // // optional string serviceSubject = 51000; E_ServiceSubject = &file_nrpc_proto_extTypes[4] // Parameters included in the subject at the service level // // repeated string serviceSubjectParams = 51001; E_ServiceSubjectParams = &file_nrpc_proto_extTypes[5] )
Extension fields to descriptor.ServiceOptions.
var ( // A custom subject to use instead of (methor name + methodSubjectRule) // // optional string methodSubject = 52000; E_MethodSubject = &file_nrpc_proto_extTypes[6] // Parameters included in the subject at the method level // // repeated string methodSubjectParams = 52001; E_MethodSubjectParams = &file_nrpc_proto_extTypes[7] // If true, the method returns a stream of reply messages instead of just one // // optional bool streamedReply = 52002; E_StreamedReply = &file_nrpc_proto_extTypes[8] )
Extension fields to descriptor.MethodOptions.
var ErrCanceled = errors.New("Call canceled")
var ErrEOS = errors.New("End of stream")
var ErrStreamInvalidMsgCount = errors.New("Stream reply received an incorrect number of messages")
ErrStreamInvalidMsgCount is when a stream reply gets a wrong number of messages
var File_nrpc_proto protoreflect.FileDescriptor
Functions ¶
func MarshalErrorResponse ¶
func ParseSubject ¶
func ParseSubjectTail ¶
Types ¶
type ContextKey ¶
type ContextKey int
ContextKey type for storing values into context.Context
const ( // RequestContextKey is the key for string the request into the context RequestContextKey ContextKey = iota )
type Error ¶
type Error struct { Type Error_Type `protobuf:"varint,1,opt,name=type,proto3,enum=nrpc.Error_Type" json:"type,omitempty"` Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` MsgCount uint32 `protobuf:"varint,3,opt,name=msgCount,proto3" json:"msgCount,omitempty"` // contains filtered or unexported fields }
func CaptureErrors ¶
CaptureErrors runs a handler and convert error and panics into proper Error
func (*Error) Descriptor
deprecated
func (*Error) GetMessage ¶
func (*Error) GetMsgCount ¶
func (*Error) GetType ¶
func (x *Error) GetType() Error_Type
func (*Error) ProtoMessage ¶
func (*Error) ProtoMessage()
func (*Error) ProtoReflect ¶
func (x *Error) ProtoReflect() protoreflect.Message
type Error_Type ¶
type Error_Type int32
const ( Error_CLIENT Error_Type = 0 Error_SERVER Error_Type = 1 Error_EOS Error_Type = 3 Error_SERVERTOOBUSY Error_Type = 4 )
func (Error_Type) Descriptor ¶
func (Error_Type) Descriptor() protoreflect.EnumDescriptor
func (Error_Type) Enum ¶
func (x Error_Type) Enum() *Error_Type
func (Error_Type) EnumDescriptor
deprecated
func (Error_Type) EnumDescriptor() ([]byte, []int)
Deprecated: Use Error_Type.Descriptor instead.
func (Error_Type) Number ¶
func (x Error_Type) Number() protoreflect.EnumNumber
func (Error_Type) String ¶
func (x Error_Type) String() string
func (Error_Type) Type ¶
func (Error_Type) Type() protoreflect.EnumType
type Heartbeat ¶ added in v0.0.3
type Heartbeat struct { Lastbeat bool `protobuf:"varint,1,opt,name=lastbeat,proto3" json:"lastbeat,omitempty"` // contains filtered or unexported fields }
func (*Heartbeat) Descriptor
deprecated
added in
v0.0.3
func (*Heartbeat) GetLastbeat ¶ added in v0.0.3
func (*Heartbeat) ProtoMessage ¶ added in v0.0.3
func (*Heartbeat) ProtoMessage()
func (*Heartbeat) ProtoReflect ¶ added in v0.0.3
func (x *Heartbeat) ProtoReflect() protoreflect.Message
type KeepStreamAlive ¶
type KeepStreamAlive struct {
// contains filtered or unexported fields
}
func NewKeepStreamAlive ¶
func NewKeepStreamAlive(nc NatsConn, subject string, encoding string, onError func()) *KeepStreamAlive
func (*KeepStreamAlive) Stop ¶
func (k *KeepStreamAlive) Stop()
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) Subscribe(subj string, handler nats.MsgHandler) (*nats.Subscription, error) ChanSubscribe(subj string, ch chan *nats.Msg) (*nats.Subscription, error) SubscribeSync(subj string) (*nats.Subscription, error) QueueSubscribe(subj, queue string, handler nats.MsgHandler) (*nats.Subscription, error) ChanQueueSubscribe(subj, queue string, ch chan *nats.Msg) (*nats.Subscription, error) QueueSubscribeSync(subj, queue string) (*nats.Subscription, error) }
type NoReply ¶
type NoReply struct {
// contains filtered or unexported fields
}
func (*NoReply) Descriptor
deprecated
func (*NoReply) ProtoMessage ¶
func (*NoReply) ProtoMessage()
func (*NoReply) ProtoReflect ¶
func (x *NoReply) ProtoReflect() protoreflect.Message
type NoRequest ¶
type NoRequest struct {
// contains filtered or unexported fields
}
func (*NoRequest) Descriptor
deprecated
func (*NoRequest) ProtoMessage ¶
func (*NoRequest) ProtoMessage()
func (*NoRequest) ProtoReflect ¶
func (x *NoRequest) ProtoReflect() protoreflect.Message
type ReplyInboxMaker ¶
ReplyInboxMaker returns a new inbox subject for a given nats connection.
var GetReplyInbox ReplyInboxMaker = func(NatsConn) string {
return nats.NewInbox()
}
GetReplyInbox is used by StreamCall to get a inbox subject It can be changed by a client lib that needs custom inbox subjects
type Request ¶
type Request struct { Context context.Context Conn NatsConn KeepStreamAlive *KeepStreamAlive StreamContext context.Context StreamCancel func() StreamMsgCount uint32 Subject string MethodName string SubjectTail []string CreatedAt time.Time StartedAt time.Time Encoding string NoReply bool ReplySubject string PackageParams map[string]string ServiceParams map[string]string AfterReply func(r *Request, success bool, replySuccess bool) Handler func(context.Context) (proto.Message, error) // contains filtered or unexported fields }
Request is a server-side incoming request
func GetRequest ¶
GetRequest returns the Request associated with a context, or nil if absent
func NewRequest ¶
NewRequest creates a Request instance
func (*Request) EnableStreamedReply ¶
func (r *Request) EnableStreamedReply()
EnableStreamedReply enables the streamed reply mode
func (*Request) PackageParam ¶
PackageParam returns a package parameter value, or "" if absent
func (*Request) Run ¶
Run the handler and capture any error. Returns the response or the error that should be returned to the caller
func (*Request) RunAndReply ¶
func (r *Request) RunAndReply()
RunAndReply calls Run() and send the reply back to the caller
func (*Request) SendErrorTooBusy ¶
SendErrorTooBusy cancels the request with a 'SERVERTOOBUSY' error
func (*Request) SendStreamReply ¶
SendStreamReply send a reply a part of a stream
func (*Request) ServiceParam ¶
ServiceParam returns a package parameter value, or "" if absent
func (*Request) SetPackageParam ¶
SetPackageParam sets a package param value
func (*Request) SetServiceParam ¶
SetServiceParam sets a service param value
func (*Request) StreamedReply ¶
StreamedReply returns true if the request reply is streamed
type StreamCallSubscription ¶
type StreamCallSubscription struct {
// contains filtered or unexported fields
}
func StreamCall ¶
type SubjectRule ¶
type SubjectRule int32
const ( SubjectRule_COPY SubjectRule = 0 SubjectRule_TOLOWER SubjectRule = 1 )
func (SubjectRule) Descriptor ¶
func (SubjectRule) Descriptor() protoreflect.EnumDescriptor
func (SubjectRule) Enum ¶
func (x SubjectRule) Enum() *SubjectRule
func (SubjectRule) EnumDescriptor
deprecated
func (SubjectRule) EnumDescriptor() ([]byte, []int)
Deprecated: Use SubjectRule.Descriptor instead.
func (SubjectRule) Number ¶
func (x SubjectRule) Number() protoreflect.EnumNumber
func (SubjectRule) String ¶
func (x SubjectRule) String() string
func (SubjectRule) Type ¶
func (SubjectRule) Type() protoreflect.EnumType
type Void ¶
type Void struct {
// contains filtered or unexported fields
}
func (*Void) Descriptor
deprecated
func (*Void) ProtoMessage ¶
func (*Void) ProtoMessage()
func (*Void) ProtoReflect ¶
func (x *Void) ProtoReflect() protoreflect.Message
type WorkerPool ¶
WorkerPool is a pool of workers
func NewWorkerPool ¶
func NewWorkerPool( ctx context.Context, size uint, maxPending uint, maxPendingDuration time.Duration, ) *WorkerPool
NewWorkerPool creates a pool of workers
func (*WorkerPool) Close ¶
func (pool *WorkerPool) Close(timeout time.Duration)
Close stops all the workers and wait for their completion If the workers do not stop before the timeout, their context is canceled Will never return if a request ignores the context
func (*WorkerPool) QueueRequest ¶
func (pool *WorkerPool) QueueRequest(request *Request) error
QueueRequest adds a request to the queue Send a SERVERTOOBUSY error to the client if the queue is full
func (*WorkerPool) SetMaxPending ¶
func (pool *WorkerPool) SetMaxPending(value uint)
SetMaxPending changes the queue size
func (*WorkerPool) SetMaxPendingDuration ¶
func (pool *WorkerPool) SetMaxPendingDuration(value time.Duration)
SetMaxPendingDuration changes the max pending delay
func (*WorkerPool) SetSize ¶
func (pool *WorkerPool) SetSize(size uint)
SetSize changes the number of workers
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
alloptions
Package main generated by protoc-gen-nrpc.
|
Package main generated by protoc-gen-nrpc. |
helloworld/helloworld
Package helloworld generated by protoc-gen-nrpc.
|
Package helloworld generated by protoc-gen-nrpc. |
metrics_helloworld/helloworld
Package helloworld generated by protoc-gen-nrpc.
|
Package helloworld generated by protoc-gen-nrpc. |
nooption
Package nooption generated by protoc-gen-nrpc.
|
Package nooption generated by protoc-gen-nrpc. |
bindata
Package bindata generated by go-bindata.// sources: assets/nrpc.tmpl
|
Package bindata generated by go-bindata.// sources: assets/nrpc.tmpl |