events

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package events provides the eventer object which is responsible for setting up the watermill router and handling the incoming events

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRetriable is an error that may be retried. All other errors encountered
	// by watermill be simply logged and ignored.
	ErrRetriable = errors.New("retriable error")
)

Functions

func NewRetriableError added in v0.0.3

func NewRetriableError(sfmt string, args ...any) error

NewRetriableError creates a new retriable error

Types

type Consumer

type Consumer interface {
	Register(Registrar)
}

Consumer is an interface implemented by components which wish to consume events. Once a component has implemented the consumer interface, it can be registered with an event router using the HandleAll interface.

type Eventer

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

Eventer is a wrapper over the relevant eventing objects in such a way that they can be easily accessible and configurable.

func Setup

func Setup() (*Eventer, error)

Setup creates an Eventer object which isolates the watermill setup code TODO: pass in logger

func (*Eventer) Close

func (e *Eventer) Close() error

Close closes the router

func (*Eventer) ConsumeEvents

func (e *Eventer) ConsumeEvents(consumers ...Consumer)

ConsumeEvents allows registration of multiple consumers easily

func (*Eventer) Publish

func (e *Eventer) Publish(topic string, messages ...*message.Message) error

Publish implements message.Publisher

func (*Eventer) Register

func (e *Eventer) Register(
	topic string,
	handler message.NoPublishHandlerFunc,
)

Register subscribes to a topic and handles incoming messages

func (*Eventer) Run

func (e *Eventer) Run(ctx context.Context) error

Run runs the router, blocks until the router is closed

func (*Eventer) Running

func (e *Eventer) Running() chan struct{}

Running returns a channel which allows you to wait until the event router has started.

type Handler

type Handler = message.NoPublishHandlerFunc

Handler is an alias for the watermill handler type, which is both wordy and may be detail we don't want to expose.

type Registrar

type Registrar interface {
	// Register requests that the message router calls handler for each message on topic.
	// It is valid to call Register multiple times with the same topic and different handler
	// functions, or to call Register multiple times with different topics and the same
	// handler function.  It's allowed to call Register with both argument the same, but
	// then events will be delivered twice to the handler, which is probably not what you want.
	Register(topic string, handler Handler)

	// HandleAll registers all the consumers with the registrar
	// TODO: should this be a different interface?
	ConsumeEvents(consumers ...Consumer)
}

Registrar provides an interface which allows an event router to expose itself to event consumers.

Jump to

Keyboard shortcuts

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