messenger

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 1 Imported by: 3

README

Go messenger

Glossary

Bus

The bus is used to dispatch messages. The behavior of the bus is in its ordered middleware stack. The component comes with a set of middleware that you can use.

Envelope

Envelope is a wrapper for messages dispatched into the bus. Envelopes can be wrapped into more envelopes each of them additional information to it.

Matcher

Matchers are used by middlewares to filter envelopes that should be handled by them.

Middleware

Middleware can access the message and its wrapper (the envelope) while it is dispatched through the bus. Literally "the software in the middle", those are not about core concerns (business logic) of an application. Instead, they are crosscutting concerns applicable throughout the application and affecting the entire message bus. For instance: logging, validating a message, starting a transaction, ... They are also responsible for calling the next middleware in the chain, which means they can tweak the envelope, by adding headers to it or even replacing it, as well as interrupt the middleware chain. Middleware are called both when a message is originally dispatched and again later when a message is received from transport.

Handler

Responsible for handling messages using the business logic applicable to the messages.

Sender

Responsible for sending messages to something. This something can be a message broker or a third party API for example.

Receiver

Responsible for retrieving messages from external source. This can be a message queue puller or an API endpoint for example. Receivers also responsible for acking or rejecting messages received by them.

Bridge

Is responsible for connecting between a receiver and a bus. They get messages from receivers and dispatch them into the bus.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	Dispatch(ctx context.Context, e Envelope)
}

type Envelope

type Envelope interface {
	Message() interface{}
	Headers() map[string][]string
	Header(name string) []string
	HasHeader(name string) bool
	LastHeader(name string) (string, bool)
	FirstHeader(name string) (string, bool)
	Is(e Envelope) bool
}

type Matcher

type Matcher interface {
	Matches(e Envelope) bool
}

type Middleware

type Middleware interface {
	Handle(ctx context.Context, bus Dispatcher, e Envelope, next NextFunc)
}

type NextFunc

type NextFunc func(ctx context.Context, e Envelope)

type Receiver

type Receiver interface {
	Receive(ctx context.Context) (<-chan Envelope, error)
	Ack(ctx context.Context, e Envelope) error
	Nack(ctx context.Context, e Envelope) error
}

type Sender

type Sender interface {
	Send(ctx context.Context, e Envelope) error
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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