xpubsub

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const MessageIDKey ctxKeyMessageID = 0

MessageIDKey is the key that holds the unique request ID in a request context.

Variables

This section is empty.

Functions

func CtxSubscriptionID

func CtxSubscriptionID(ctx context.Context) string

CtxSubscriptionID gets the subscription id from the given context.

func CtxTopic

func CtxTopic(ctx context.Context) string

CtxTopic gets the subscription topic from the given context.

func GetMessageID

func GetMessageID(ctx context.Context) string

GetMessageID returns a message ID from the given context if one is present. Returns the empty string if a message ID cannot be found.

func MarshalMessage

func MarshalMessage(c codec.Codec, msg interface{}) (*pubsub.Message, error)

MarshalMessage is a function that marshals input message structure into the pubsub.Message body.

func UnmarshalMessage

func UnmarshalMessage(c codec.Codec, msg *pubsub.Message, dst interface{}) error

UnmarshalMessage unmarshals message body into provided destination using given codec.

Types

type ChainHandler

type ChainHandler struct {
	Middlewares Middlewares
	Endpoint    Handler
	// contains filtered or unexported fields
}

ChainHandler is a http.Handler with support for handler composition and execution.

func (*ChainHandler) Handle

func (c *ChainHandler) Handle(ctx context.Context, m *pubsub.Message) error

Handle implements Handler interface.

type Handler

type Handler interface {
	Handle(ctx context.Context, m *pubsub.Message) error
}

Handler is an interface used by the Mux that is responsible for handling the Message.

func Acker

func Acker(h Handler) Handler

Acker is a middleware that checks if the subsequent handlers returns an error and on success Ackes them. In case of failure it Nacks the message if it is possible.

func ContextMetadata added in v0.0.3

func ContextMetadata(next Handler) Handler

ContextMetadata sets up the metadata from the message in the context.

func Logger

func Logger(next Handler) Handler

Logger is a middleware function that is used for trace logging incoming message on subscriptions.

func MessageID

func MessageID(next Handler) Handler

MessageID is a middleware function that generates new request id and puts it into message context, A message ID is a string of the form "host.example.com/random-0001", where "random" is a base62 random string that uniquely identifies this go process, and where the last number is an atomically incremented request counter. The concept and implementation of this request id is based on the brilliant golang library: github.com/go-chi/chi.

func Recoverer

func Recoverer(h Handler) Handler

Recoverer recovers from any panic in the handler and appends RecoveredPanicError with the stacktrace to any error returned from the handler.

type HandlerFunc

type HandlerFunc func(ctx context.Context, m *pubsub.Message) error

HandlerFunc is a function used to handle messages.

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(ctx context.Context, m *pubsub.Message) error

type MessageTyper added in v0.0.6

type MessageTyper interface {
	MessageType() string
}

MessageTyper is an interface used by the event messages that defines the type of the message.

type Middleware

type Middleware func(next Handler) Handler

Middleware is a middleware function type.

type Middlewares

type Middlewares []Middleware

func (Middlewares) Handler

func (mws Middlewares) Handler(h Handler) Handler

func (Middlewares) HandlerFunc

func (mws Middlewares) HandlerFunc(h HandlerFunc) Handler

type Mux

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

Mux is a subscriber router. It provides an easy interfaces for starting and listening on the subscriptions. Implements xservice.RunnerCloser interface.

func NewMux

func NewMux() *Mux

NewMux creates a new mux that will register subscriptions using provided subscriber factory.

func (*Mux) Close

func (m *Mux) Close(ctx context.Context) error

Close the pubsub mux subscriptions.

func (*Mux) Run

func (m *Mux) Run() error

Run starts the router and begin on listening for given subscriptions.

func (*Mux) Subscribe

func (m *Mux) Subscribe(topic string, hf HandlerFunc)

Subscribe registers topic subscriber that handles the message using provided handler with given options.

func (*Mux) Subscription

func (m *Mux) Subscription(sub *pubsub.Subscription, hf HandlerFunc, topic ...string)

Subscription registers subscription with specific handler. Optionally the topic name might be set for the logging and context passing purpose.

func (*Mux) Use

func (m *Mux) Use(middleware ...Middleware)

Use provides middlewares to be used for all routes and children groups.

func (*Mux) With

func (m *Mux) With(middlewares ...Middleware) *Mux

With sets the middlewares for the resultant Mux that would be used exclusively in its and it's children context.

func (*Mux) WithMaxHandlers

func (m *Mux) WithMaxHandlers(maxHandlers int) *Mux

WithMaxHandlers sets up the maximum concurrent handlers number for the resultant Mux that would be used exclusively in its and it's children context.

type Topic

type Topic interface {
	Send(ctx context.Context, m *pubsub.Message) error
	Shutdown(ctx context.Context) error
	ErrorAs(err error, i interface{}) bool
	As(i interface{}) bool
}

Topic is the interface implementation of the pubsub.Topic. It allows to easily mockup the pubsub.Topic by replacing direct implementation.

type TopicPublisher added in v0.0.6

type TopicPublisher struct {
	Topic Topic
	Codec codec.Codec
}

TopicPublisher is a structure responsible for publishing new topic messages.

func (*TopicPublisher) Publish added in v0.0.6

func (t *TopicPublisher) Publish(ctx context.Context, msg MessageTyper) error

Publish prepares pubsub.Message with the context stored metadata and publishes into given topic.

Directories

Path Synopsis
Package mockpubsub is a generated GoMock package.
Package mockpubsub is a generated GoMock package.
pubsubmiddleware

Jump to

Keyboard shortcuts

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