kit: github.com/go-kit/kit/transport/nats Index | Files

package nats

import "github.com/go-kit/kit/transport/nats"

Package nats provides a NATS transport.

Index

Package Files

doc.go encode_decode.go publisher.go request_response_funcs.go subscriber.go

func DefaultErrorEncoder Uses

func DefaultErrorEncoder(_ context.Context, err error, reply string, nc *nats.Conn)

DefaultErrorEncoder writes the error to the subscriber reply.

func EncodeJSONRequest Uses

func EncodeJSONRequest(_ context.Context, msg *nats.Msg, request interface{}) error

EncodeJSONRequest is an EncodeRequestFunc that serializes the request as a JSON object to the Data of the Msg. Many JSON-over-NATS services can use it as a sensible default.

func EncodeJSONResponse Uses

func EncodeJSONResponse(_ context.Context, reply string, nc *nats.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 Uses

func NopRequestDecoder(_ context.Context, _ *nats.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.

type DecodeRequestFunc Uses

type DecodeRequestFunc func(context.Context, *nats.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 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 Uses

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

DecodeResponseFunc extracts a user-domain response object from an NATS response object. It's designed to be used in NATS 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 Uses

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

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

type EncodeResponseFunc Uses

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

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

type ErrorEncoder Uses

type ErrorEncoder func(ctx context.Context, err error, reply string, nc *nats.Conn)

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 Publisher Uses

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

Publisher wraps a URL and provides a method that implements endpoint.Endpoint.

func NewPublisher Uses

func NewPublisher(
    publisher *nats.Conn,
    subject string,
    enc EncodeRequestFunc,
    dec DecodeResponseFunc,
    options ...PublisherOption,
) *Publisher

NewClient constructs a usable Publisher for a single remote method.

func (Publisher) Endpoint Uses

func (p Publisher) Endpoint() endpoint.Endpoint

Endpoint returns a usable endpoint that invokes the remote endpoint.

type PublisherOption Uses

type PublisherOption func(*Publisher)

PublisherOption sets an optional parameter for clients.

func PublisherAfter Uses

func PublisherAfter(after ...PublisherResponseFunc) PublisherOption

PublisherAfter sets the ClientResponseFuncs applied to the incoming NATS request prior to it being decoded. This is useful for obtaining anything off of the response and adding onto the context prior to decoding.

func PublisherBefore Uses

func PublisherBefore(before ...RequestFunc) PublisherOption

PublisherBefore sets the RequestFuncs that are applied to the outgoing NATS request before it's invoked.

func PublisherTimeout Uses

func PublisherTimeout(timeout time.Duration) PublisherOption

PublisherTimeout sets the available timeout for NATS request.

type PublisherResponseFunc Uses

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

PublisherResponseFunc may take information from an NATS 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 Uses

type RequestFunc func(context.Context, *nats.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 Uses

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

Subscriber wraps an endpoint and provides nats.MsgHandler.

func NewSubscriber Uses

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

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

func (Subscriber) ServeMsg Uses

func (s Subscriber) ServeMsg(nc *nats.Conn) func(msg *nats.Msg)

ServeMsg provides nats.MsgHandler.

type SubscriberOption Uses

type SubscriberOption func(*Subscriber)

SubscriberOption sets an optional parameter for subscribers.

func SubscriberAfter Uses

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 Uses

func SubscriberBefore(before ...RequestFunc) SubscriberOption

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

func SubscriberErrorEncoder Uses

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 SubscriberErrorLogger Uses

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.

type SubscriberResponseFunc Uses

type SubscriberResponseFunc func(context.Context, *nats.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.

Package nats imports 6 packages (graph) and is imported by 1 packages. Updated 2018-04-28. Refresh now. Tools for package owners.