projection

package
v0.1.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package projection contains a Projection interface, one for left-folding events to execute side effects, and one for Domain Read Models.

Index

Constants

View Source
const DefaultRunnerBufferSize = 32

DefaultRunnerBufferSize is the default size for the buffered channels opened by a Runner instance, if not specified.

Variables

This section is empty.

Functions

func Checkpoint

func Checkpoint(ctx context.Context)

Checkpoint should be used in a projection.Apply method to signal to a projection.Runner that the event processed should not checkpointed.

NOTE: this is currently the default behavior of projection.Runner, so using this method is not usually necessary.

func DoNotCheckpoint

func DoNotCheckpoint(ctx context.Context)

DoNotCheckpoint should be used in a projection.Apply method to signal to a projection.Runner that the event processed should not be checkpointed.

Types

type Applier

type Applier interface {
	Apply(context.Context, eventstore.Event) error
}

Applier is a segregated Projection interface that focuses on applying Events to a Projection state to trigger a side effect.

Applier implementations do not necessarily require to be Domain Read Models, and thus implementing the query.Handler interface.

Examples of pure Appliers are Process Managers, which are long running Event listeners that trigger side effects by orchestrating compensating actions.

Use a Runner with a tailored Subscription type to make use of an Applier instance.

type ApplierFunc

type ApplierFunc func(ctx context.Context, event eventstore.Event) error

ApplierFunc is a functional Applier type implementation.

func (ApplierFunc) Apply

func (fn ApplierFunc) Apply(ctx context.Context, event eventstore.Event) error

Apply executes the function pointed by the current value.

type Projection

type Projection interface {
	query.Handler
	Applier
}

Projection represents a Domain Read Model, whose state is updated through means of persisted Events coming form the Event Store (the Applier interface), and can be accessed using a Domain Query (the query.Handler interface).

Use a Runner with a tailored Subscription type to make use of a Projection. Usually, if long-lived and stored in persistent storage, it's suggested to use a Catch-up Subscription with a Projection, using a persisted Checkpointer to survive application restarts.

type Runner

type Runner struct {
	Applier      Applier
	Subscription subscription.Subscription
	BufferSize   int
	Logger       logger.Logger
}

Runner is an infrastructural component that orchestrates the state update of an Applier or a Projection using the provided Subscription, to subscribe to incoming events from the Event Store.

func (Runner) Run

func (r Runner) Run(ctx context.Context) error

Run starts listening to Events from the provided Subscription and sinking them to the Applier instance to trigger state change.

Run is a blocking call, that will exit when either the Applier returns an error, or the Subscription stops.

Run uses buffered channels to coordinate events communication between components, using the value specified in BufferSize, if any, or DefaultRunnerBufferSize otherwise.

To stop the Runner, cancel the provided context. If the error returned upon exit is context.Canceled, that usually represent a case of normal operation, so it could be treated as a non-error.

Jump to

Keyboard shortcuts

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