dispatcher

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package dispatcher provides a simple mechanism for dispatching domain events locally using a simple in-memory broker.

Dispatcher must only be used to communicate between different parts of the same application or "Bounded Context". For communicating between different applications or services, please use a message broker instead.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHandlerFunc = errors.New("invalid handler function")

ErrInvalidHandlerFunc returned when subscribing with an invalid handler function.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher interface {
	// Dispatch dispatches an event to active subscribers. If this method fails,
	// means that the event was not delivered to any listener and could be
	// retried.
	Dispatch(ctx context.Context, event events.Event) error

	// Subscribe registers a handler function to react on specific events.
	// The handler function must have the following signature:
	//
	// 	func(ctx context.Context, event <T>) error
	//
	// Where <T> is the type of the event to be handled. This type cannot be
	// a pointer. This enforces the immutability of the events when dispatched.
	//
	// Examples:
	//
	// 	func(ctx context.Context, event string) error
	// 	func(ctx context.Context, event myMessage) error
	Subscribe(ctx context.Context, handlerFn interface{}) error
}

Dispatcher defines a component capable of registering listeners and dispatching events to them.

func NewMemoryDispatcher

func NewMemoryDispatcher() Dispatcher

NewMemoryDispatcher builds a dispatcher that moves events using local memory in a thread-safe way.

Jump to

Keyboard shortcuts

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