projection

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OffsetStore

type OffsetStore struct{}

OffsetStore is a MySQL-backed implementation of Ax's projection.OffsetStore interface.

func (OffsetStore) IncrementOffset

func (s OffsetStore) IncrementOffset(
	ctx context.Context,
	ptx persistence.Tx,
	pk string,
	c uint64,
) error

IncrementOffset increments the offset at which a consumer should resume reading from the stream by one.

pk is the projector's persitence key. c is the offset that is currently stored, as returned by LoadOffset(). If c is not the offset that is currently stored, the increment fails and a non-nil error is returned.

func (OffsetStore) LoadOffset

func (OffsetStore) LoadOffset(
	ctx context.Context,
	ds persistence.DataStore,
	pk string,
) (uint64, error)

LoadOffset returns the offset at which a consumer should resume reading from the stream.

pk is the projector's persistence key.

type ReadModel

type ReadModel interface {
	// PersistenceKey returns a unique name for the read-model.
	//
	// The persistence key is used to relate persisted data with the read-model
	// implementation that owns it. Persistence keys should not be changed once
	// the read-model's projector has been started.
	PersistenceKey() string
}

ReadModel is an interface for application defined read-model projectors.

Read-model projectors are a specialization of projectors that are designed to produce an application read-model from a series of events, and persist that read-model in a MySQL database.

For each event type to be applied to the read-model, the projector must implement an "apply" method that adheres to one of the following signatures:

func (ctx context.Context, tx *sql.Tx, ev *<T>) error
func (ctx context.Context, tx *sql.Tx, ev *<T>, mctx ax.MessageContext) error

Where T is a struct type that implements ax.Event.

Applier methods are responsible for mutating the read-model state. The appropriate applier is called for each message encountered in the stream. Any messages in the stream that do not have an associated applier method are ignored.

The names of handler methods are meaningful. Each handler method's name must begin with "When". By convention these prefixes are followed by the message name, such as:

func (*BankAccount) WhenAccountCredited(*messages.AccountCredited)

type ReadModelProjector

type ReadModelProjector struct {
	ReadModel  ReadModel
	EventTypes ax.MessageTypeSet
	Apply      typeswitch.Switch
}

ReadModelProjector is a projector that applies events to a ReadModel.

func NewReadModelProjector

func NewReadModelProjector(rm ReadModel) *ReadModelProjector

NewReadModelProjector returns a new projector that applies events to a read-model.

func (ReadModelProjector) ApplyMessage

func (p ReadModelProjector) ApplyMessage(ctx context.Context, mctx ax.MessageContext) error

ApplyMessage invokes application-defined logic that updates the application state to reflect the occurrence of a message.

It may panic if env.Message is not one of the types described by MessageTypes().

func (ReadModelProjector) MessageTypes

func (p ReadModelProjector) MessageTypes() ax.MessageTypeSet

MessageTypes returns the set of messages that the projector intends to handle.

The return value should be constant as it may be cached.

func (ReadModelProjector) PersistenceKey

func (p ReadModelProjector) PersistenceKey() string

PersistenceKey returns a unique name for the projector.

The persistence key is used to relate persisted data with the projector implementation that owns it. Persistence keys should not be changed once a projection has been started.

Jump to

Keyboard shortcuts

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