nrpc: github.com/rapidloop/nrpc Index | Files

package nrpc

import "github.com/rapidloop/nrpc"

Index

Package Files

nrpc.go nrpc.pb.go

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

func Call Uses

func Call(req proto.Message, rep proto.Message, nc NatsConn, subject string, encoding string, timeout time.Duration) error

func Marshal Uses

func Marshal(encoding string, msg proto.Message) ([]byte, error)

func MarshalErrorResponse Uses

func MarshalErrorResponse(encoding string, repErr *Error) ([]byte, error)

func ParseSubject Uses

func ParseSubject(
    packageSubject string, packageParamsCount int,
    serviceSubject string, serviceParamsCount int,
    subject string,
) (packageParams []string, serviceParams []string,
    name string, tail []string, err error,
)

func ParseSubjectTail Uses

func ParseSubjectTail(
    methodParamsCount int,
    tail []string,
) (
    methodParams []string, encoding string, err error,
)

func Publish Uses

func Publish(resp proto.Message, withError *Error, nc NatsConn, subject string, encoding string) error

func Unmarshal Uses

func Unmarshal(encoding string, data []byte, msg proto.Message) error

func UnmarshalResponse Uses

func UnmarshalResponse(encoding string, data []byte, msg proto.Message) error

type ContextKey Uses

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 Uses

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 Uses

func CaptureErrors(fn func() (proto.Message, error)) (msg proto.Message, replyError *Error)

CaptureErrors runs a handler and convert error and panics into proper Error

func (*Error) Descriptor Uses

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

Deprecated: Use Error.ProtoReflect.Descriptor instead.

func (*Error) Error Uses

func (e *Error) Error() string

func (*Error) GetMessage Uses

func (x *Error) GetMessage() string

func (*Error) GetMsgCount Uses

func (x *Error) GetMsgCount() uint32

func (*Error) GetType Uses

func (x *Error) GetType() Error_Type

func (*Error) ProtoMessage Uses

func (*Error) ProtoMessage()

func (*Error) ProtoReflect Uses

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

func (*Error) Reset Uses

func (x *Error) Reset()

func (*Error) String Uses

func (x *Error) String() string

type Error_Type Uses

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 Uses

func (Error_Type) Descriptor() protoreflect.EnumDescriptor

func (Error_Type) Enum Uses

func (x Error_Type) Enum() *Error_Type

func (Error_Type) EnumDescriptor Uses

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

Deprecated: Use Error_Type.Descriptor instead.

func (Error_Type) Number Uses

func (x Error_Type) Number() protoreflect.EnumNumber

func (Error_Type) String Uses

func (x Error_Type) String() string

func (Error_Type) Type Uses

func (Error_Type) Type() protoreflect.EnumType

type HeartBeat Uses

type HeartBeat struct {
    Lastbeat bool `protobuf:"varint,1,opt,name=lastbeat,proto3" json:"lastbeat,omitempty"`
    // contains filtered or unexported fields
}

func (*HeartBeat) Descriptor Uses

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

Deprecated: Use HeartBeat.ProtoReflect.Descriptor instead.

func (*HeartBeat) GetLastbeat Uses

func (x *HeartBeat) GetLastbeat() bool

func (*HeartBeat) ProtoMessage Uses

func (*HeartBeat) ProtoMessage()

func (*HeartBeat) ProtoReflect Uses

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

func (*HeartBeat) Reset Uses

func (x *HeartBeat) Reset()

func (*HeartBeat) String Uses

func (x *HeartBeat) String() string

type KeepStreamAlive Uses

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

func NewKeepStreamAlive Uses

func NewKeepStreamAlive(nc NatsConn, subject string, encoding string, onError func()) *KeepStreamAlive

func (*KeepStreamAlive) Stop Uses

func (k *KeepStreamAlive) Stop()

type NatsConn Uses

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)
    Subscribe(subj string, handler nats.MsgHandler) (*nats.Subscription, error)
    SubscribeSync(subj string) (*nats.Subscription, error)
}

type NoReply Uses

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

func (*NoReply) Descriptor Uses

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

Deprecated: Use NoReply.ProtoReflect.Descriptor instead.

func (*NoReply) ProtoMessage Uses

func (*NoReply) ProtoMessage()

func (*NoReply) ProtoReflect Uses

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

func (*NoReply) Reset Uses

func (x *NoReply) Reset()

func (*NoReply) String Uses

func (x *NoReply) String() string

type NoRequest Uses

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

func (*NoRequest) Descriptor Uses

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

Deprecated: Use NoRequest.ProtoReflect.Descriptor instead.

func (*NoRequest) ProtoMessage Uses

func (*NoRequest) ProtoMessage()

func (*NoRequest) ProtoReflect Uses

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

func (*NoRequest) Reset Uses

func (x *NoRequest) Reset()

func (*NoRequest) String Uses

func (x *NoRequest) String() string

type ReplyInboxMaker Uses

type ReplyInboxMaker func(NatsConn) string

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 Uses

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 Uses

func GetRequest(ctx context.Context) *Request

GetRequest returns the Request associated with a context, or nil if absent

func NewRequest Uses

func NewRequest(ctx context.Context, conn NatsConn, subject string, replySubject string) *Request

NewRequest creates a Request instance

func (*Request) Elapsed Uses

func (r *Request) Elapsed() time.Duration

Elapsed duration since request was started

func (*Request) EnableStreamedReply Uses

func (r *Request) EnableStreamedReply()

EnableStreamedReply enables the streamed reply mode

func (*Request) PackageParam Uses

func (r *Request) PackageParam(key string) string

PackageParam returns a package parameter value, or "" if absent

func (*Request) Run Uses

func (r *Request) Run() (msg proto.Message, replyError *Error)

Run the handler and capture any error. Returns the response or the error that should be returned to the caller

func (*Request) RunAndReply Uses

func (r *Request) RunAndReply()

RunAndReply calls Run() and send the reply back to the caller

func (*Request) SendErrorTooBusy Uses

func (r *Request) SendErrorTooBusy(msg string) error

SendErrorTooBusy cancels the request with a 'SERVERTOOBUSY' error

func (*Request) SendReply Uses

func (r *Request) SendReply(resp proto.Message, withError *Error) error

SendReply sends a reply to the caller

func (*Request) SendStreamReply Uses

func (r *Request) SendStreamReply(msg proto.Message)

SendStreamReply send a reply a part of a stream

func (*Request) ServiceParam Uses

func (r *Request) ServiceParam(key string) string

ServiceParam returns a package parameter value, or "" if absent

func (*Request) SetPackageParam Uses

func (r *Request) SetPackageParam(key, value string)

SetPackageParam sets a package param value

func (*Request) SetServiceParam Uses

func (r *Request) SetServiceParam(key, value string)

SetServiceParam sets a service param value

func (*Request) StreamedReply Uses

func (r *Request) StreamedReply() bool

StreamedReply returns true if the request reply is streamed

type StreamCallSubscription Uses

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

func NewStreamCallSubscription Uses

func NewStreamCallSubscription(
    ctx context.Context, nc NatsConn, encoding string, subject string,
    timeout time.Duration,
) (*StreamCallSubscription, error)

func StreamCall Uses

func StreamCall(ctx context.Context, nc NatsConn, subject string, req proto.Message, encoding string, timeout time.Duration) (*StreamCallSubscription, error)

func (*StreamCallSubscription) Next Uses

func (sub *StreamCallSubscription) Next(rep proto.Message) error

type SubjectRule Uses

type SubjectRule int32
const (
    SubjectRule_COPY    SubjectRule = 0
    SubjectRule_TOLOWER SubjectRule = 1
)

func (SubjectRule) Descriptor Uses

func (SubjectRule) Descriptor() protoreflect.EnumDescriptor

func (SubjectRule) Enum Uses

func (x SubjectRule) Enum() *SubjectRule

func (SubjectRule) EnumDescriptor Uses

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

Deprecated: Use SubjectRule.Descriptor instead.

func (SubjectRule) Number Uses

func (x SubjectRule) Number() protoreflect.EnumNumber

func (SubjectRule) String Uses

func (x SubjectRule) String() string

func (SubjectRule) Type Uses

func (SubjectRule) Type() protoreflect.EnumType

type Void Uses

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

func (*Void) Descriptor Uses

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

Deprecated: Use Void.ProtoReflect.Descriptor instead.

func (*Void) ProtoMessage Uses

func (*Void) ProtoMessage()

func (*Void) ProtoReflect Uses

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

func (*Void) Reset Uses

func (x *Void) Reset()

func (*Void) String Uses

func (x *Void) String() string

type WorkerPool Uses

type WorkerPool struct {
    Context context.Context
    // contains filtered or unexported fields
}

WorkerPool is a pool of workers

func NewWorkerPool Uses

func NewWorkerPool(
    ctx context.Context,
    size uint,
    maxPending uint,
    maxPendingDuration time.Duration,
) *WorkerPool

NewWorkerPool creates a pool of workers

func (*WorkerPool) Close Uses

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 Uses

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 Uses

func (pool *WorkerPool) SetMaxPending(value uint)

SetMaxPending changes the queue size

func (*WorkerPool) SetMaxPendingDuration Uses

func (pool *WorkerPool) SetMaxPendingDuration(value time.Duration)

SetMaxPendingDuration changes the max pending delay

func (*WorkerPool) SetSize Uses

func (pool *WorkerPool) SetSize(size uint)

SetSize changes the number of workers

Package nrpc imports 18 packages (graph). Updated 2020-07-04. Refresh now. Tools for package owners.