events

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 20 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

View Source
const (
	ProviderDeliveryIdKey     = "id"
	ProviderTypeKey           = "provider"
	ProviderSourceKey         = "source"
	GithubWebhookEventTypeKey = "type"

	GoChannelDriver = "go-channel"
	SQLDriver       = "sql"

	DeadLetterQueueTopic = "dead_letter_queue"
	PublishedKey         = "published_at"
)

Metadata added to Messages

View Source
const (
	// ExecuteEntityEventTopic is the topic for internal webhook events
	ExecuteEntityEventTopic = "execute.entity.event"
	// FlushEntityEventTopic is the topic for flushing internal webhook events
	FlushEntityEventTopic = "flush.entity.event"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatorMiddleware added in v0.0.17

type AggregatorMiddleware interface {
	AggregateMiddleware(h message.HandlerFunc) message.HandlerFunc
}

AggregatorMiddleware is an interface that allows the eventer to add middleware to the router

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(ctx context.Context, cfg *serverconfig.EventConfig) (*Eventer, error)

Setup creates an Eventer object which isolates the watermill setup code

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,
	mdw ...message.HandlerMiddleware,
)

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 Interface added in v0.0.32

type Interface interface {
	// Publish implements message.Publisher
	Publish(topic string, messages ...*message.Message) error

	// Register subscribes to a topic and handles incoming messages
	Register(topic string, handler message.NoPublishHandlerFunc, mdw ...message.HandlerMiddleware)

	// ConsumeEvents allows registration of multiple consumers easily
	ConsumeEvents(consumers ...Consumer)
	// Close closes the router
	Close() error
	// Run runs the router, blocks until the router is closed
	Run(ctx context.Context) error

	// Running returns a channel which allows you to wait until the
	// event router has started.
	Running() chan struct{}
}

Interface provides an abstract interface over Eventer (and mocks)

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, mdw ...message.HandlerMiddleware)
}

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

Directories

Path Synopsis
Package mockevents is a generated GoMock package.
Package mockevents is a generated GoMock package.

Jump to

Keyboard shortcuts

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