stan

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package stan provides a NATS Streaming(stan) transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultErrorEncoder

func DefaultErrorEncoder(_ context.Context, err error)

DefaultErrorEncoder writes the error to the subscriber reply.

func EncodeJSONResponse

func EncodeJSONResponse(_ context.Context, sc *stan.Conn, response interface{}) error

EncodeJSONResponse is a EncodeResponseFunc that serializes the response as a JSON object to the subscriber reply. Many JSON-over services can use it as a sensible default.

func NopRequestDecoder

func NopRequestDecoder(_ context.Context, _ *stan.Msg) (interface{}, error)

NopRequestDecoder is a DecodeRequestFunc that can be used for requests that do not need to be decoded, and simply returns nil, nil.

Types

type DecodeRequestFunc

type DecodeRequestFunc func(context.Context, *stan.Msg) (request interface{}, err error)

DecodeRequestFunc extracts a user-domain request object from a publisher request object. It's designed to be used in NATS Streaming subscribers, for subscriber-side endpoints. One straightforward DecodeRequestFunc could be something that JSON decodes from the request body to the concrete response type.

type DecodeResponseFunc

type DecodeResponseFunc func(context.Context, *stan.Msg) (response interface{}, err error)

DecodeResponseFunc extracts a user-domain response object from an NATS Streaming response object. It's designed to be used in NATS Streaming publisher, for publisher-side endpoints. One straightforward DecodeResponseFunc could be something that JSON decodes from the response payload to the concrete response type.

type EncodeRequestFunc

type EncodeRequestFunc func(context.Context, *stan.Msg, interface{}) error

EncodeRequestFunc encodes the passed request object into the NATS Streaming request object. It's designed to be used in NATS Streaming publishers, for publisher-side endpoints. One straightforward EncodeRequestFunc could something that JSON encodes the object directly to the request payload.

type EncodeResponseFunc

type EncodeResponseFunc func(context.Context, *stan.Conn, interface{}) error

EncodeResponseFunc encodes the passed response object to the subscriber reply. It's designed to be used in NATS Streaming subscribers, for subscriber-side endpoints. One straightforward EncodeResponseFunc could be something that JSON encodes the object directly to the response body.

type ErrorEncoder

type ErrorEncoder func(ctx context.Context, err error)

ErrorEncoder is responsible for encoding an error to the subscriber reply. Users are encouraged to use custom ErrorEncoders to encode errors to their replies, and will likely want to pass and check for their own error types.

type PublisherResponseFunc

type PublisherResponseFunc func(context.Context, *stan.Msg) context.Context

PublisherResponseFunc may take information from an NATS Streaming request and make the response available for consumption. ClientResponseFuncs are only executed in clients, after a request has been made, but prior to it being decoded.

type RequestFunc

type RequestFunc func(context.Context, *stan.Msg) context.Context

RequestFunc may take information from a publisher request and put it into a request context. In Subscribers, RequestFuncs are executed prior to invoking the endpoint.

type Subscriber

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

Subscriber wraps an endpoint and provides stan.MsgHandler.

func NewSubscriber

func NewSubscriber(
	e endpoint.Endpoint,
	dec DecodeRequestFunc,
	enc EncodeResponseFunc,
	options ...SubscriberOption,
) *Subscriber

NewSubscriber constructs a new subscriber, which provides stan.MsgHandler and wraps the provided endpoint.

func (Subscriber) ServeMsg

func (s Subscriber) ServeMsg(sc *stan.Conn) func(msg *stan.Msg)

ServeMsg provides stan.MsgHandler.

type SubscriberFinalizerFunc

type SubscriberFinalizerFunc func(ctx context.Context, msg *stan.Msg)

ServerFinalizerFunc can be used to perform work at the end of an request from a publisher, after the response has been written to the publisher. The principal intended use is for request logging.

type SubscriberOption

type SubscriberOption func(*Subscriber)

SubscriberOption sets an optional parameter for subscribers.

func SubscriberAfter

func SubscriberAfter(after ...SubscriberResponseFunc) SubscriberOption

SubscriberAfter functions are executed on the subscriber reply after the endpoint is invoked, but before anything is published to the reply.

func SubscriberBefore

func SubscriberBefore(before ...RequestFunc) SubscriberOption

SubscriberBefore functions are executed on the publisher request object before the request is decoded.

func SubscriberErrorEncoder

func SubscriberErrorEncoder(ee ErrorEncoder) SubscriberOption

SubscriberErrorEncoder is used to encode errors to the subscriber reply whenever they're encountered in the processing of a request. Clients can use this to provide custom error formatting. By default, errors will be published with the DefaultErrorEncoder.

func SubscriberErrorHandler

func SubscriberErrorHandler(errorHandler transport.ErrorHandler) SubscriberOption

SubscriberErrorHandler is used to handle non-terminal errors. By default, non-terminal errors are ignored. This is intended as a diagnostic measure. Finer-grained control of error handling, including logging in more detail, should be performed in a custom SubscriberErrorEncoder which has access to the context.

func SubscriberErrorLogger

func SubscriberErrorLogger(logger log.Logger) SubscriberOption

SubscriberErrorLogger is used to log non-terminal errors. By default, no errors are logged. This is intended as a diagnostic measure. Finer-grained control of error handling, including logging in more detail, should be performed in a custom SubscriberErrorEncoder which has access to the context. Deprecated: Use SubscriberErrorHandler instead.

func SubscriberFinalizer

func SubscriberFinalizer(f ...SubscriberFinalizerFunc) SubscriberOption

SubscriberFinalizer is executed at the end of every request from a publisher through NATS Streaming. By default, no finalizer is registered.

type SubscriberResponseFunc

type SubscriberResponseFunc func(context.Context, *stan.Conn) context.Context

SubscriberResponseFunc may take information from a request context and use it to manipulate a Publisher. SubscriberResponseFuncs are only executed in subscribers, after invoking the endpoint but prior to publishing a reply.

Jump to

Keyboard shortcuts

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