projection

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package projection provides engine components that orchestrate the execution of projection message handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeHandler

func InitializeHandler(
	ctx context.Context,
	db *sql.DB,
	handlerConfig *config.Projection,
) error

InitializeHandler initializes the state of a projection message handler.

It is called by the engine on startup, before any components are started.

Types

type Compactor

type Compactor struct {
	// DB is the database connection used to coordinate compaction.
	DB *sql.DB

	// Handler is the projection to compact.
	Handler dogma.ProjectionMessageHandler

	// Identity is the identity of the handler.
	Identity *identitypb.Identity

	// Interval is the minimum time between successful compactions.
	Interval time.Duration

	// Timeout is the maximum time the handler is given to compact the
	// projection in a single attempt.
	Timeout time.Duration

	// Logger is the target for log messages produced by the compactor and by
	// the handler during compaction.
	Logger *slog.Logger
}

Compactor periodically compacts a projection by invoking dogma.ProjectionMessageHandler.Compact().

func (*Compactor) Run

func (c *Compactor) Run(ctx context.Context) error

Run attempts to compact the projection immediately and then once per interval until ctx is canceled. The projection is compacted at most once per interval.

It must be called at most once.

type Consumer added in v0.2.0

type Consumer struct {
	// Node is this engine's node in the cluster. Its membership determines
	// which streams this node consumes.
	Node *cluster.Node

	// EventStreams is the catalog of event streams to consume.
	EventStreams *eventstream.Catalog

	// Handler is the projection message handler to which events are
	// dispatched.
	Handler dogma.ProjectionMessageHandler

	// Identity is the identity of the handler.
	Identity *identitypb.Identity

	// Concurrency is the handler's concurrency preference.
	Concurrency dogma.ConcurrencyPreference

	// EventTypeIDs is the set of IDs of the event types that the handler
	// consumes. It must not be empty.
	EventTypeIDs *uuidcollection.Set

	// Logger is the target for log messages produced by the consumer and its
	// stream consumers.
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Consumer dispatches events from a catalog's event streams to a projection message handler.

Each stream's workload is the responsibility of one of the live nodes in the cluster, chosen by rendezvous hashing, and that node consumes the stream. While nodes are joining or leaving, more than one node may briefly consume the same stream; the handler's optimistic concurrency control ensures each event is handled once.

func (*Consumer) Run added in v0.2.0

func (c *Consumer) Run(ctx context.Context) error

Run consumes the event streams that this node is responsible for until ctx is canceled or it is unable to continue.

It must be called at most once.

Jump to

Keyboard shortcuts

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