router

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package router contains a Router interface and Mux, message handler multiplexer, to allow for multiple message handlers to be assigned to multiple queues.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHandler = errors.New("router: no handler for the incoming message has been found")

ErrNoHandler is returned by Router.Handle method when no handler has been found for the incoming message.

Functions

This section is empty.

Types

type Binder

type Binder interface {
	Bind(string, handler.Handler)
}

Binder allows to bind a queue to a message handler.

type Mux

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

Mux is a multiplexer that implements the Router interface, to support multiple message handler functions for specific queues.

func New

func New() *Mux

New returns a new Router instance.

func (*Mux) Bind

func (r *Mux) Bind(queue string, h handler.Handler)

Bind binds a message handler function to the specified queue, if the handler is not nil.

func (*Mux) Group

func (r *Mux) Group(fn func(Router)) Router

Group creates a new inline Router and fresh middleware stack, useful to group multiple handler bindings with same middlewares to be applied.

func (Mux) Handle

func (r Mux) Handle(ctx context.Context, delivery amqp.Delivery) error

Handle delegates message handling to the specific queue identified by the amqp.Delivery.ConsumerTag value.

func (*Mux) Use

func (r *Mux) Use(middlewares ...func(handler.Handler) handler.Handler)

Use appends middlewares to the Mux middleware stack.

func (*Mux) With

func (r *Mux) With(middlewares ...func(handler.Handler) handler.Handler) Binder

With adds inline middlewares for a message handler, returning a Binder interface that can be used to bind the message handler for a specific consumer.

type Router

type Router interface {
	Binder
	handler.Handler

	Group(func(Router)) Router
	Use(middlewares ...func(handler.Handler) handler.Handler)
	With(middlewares ...func(handler.Handler) handler.Handler) Binder
}

Router is a message handler extension that supports middlewares and multiple consumer bindings.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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