Nexus API Reference

PersistenceEngine
in package

FinalYes

Core engine that wraps user command+event handlers into a Behavior with automatic recovery and event persistence.

On actor start (setup phase), the engine:

  1. Loads the latest snapshot from the SnapshotStore (if available)
  2. Replays events from the EventStore (from snapshot's sequenceNr + 1)
  3. Applies each event to state using the user's eventHandler
  4. Returns a stateful Behavior for command processing

On each message, the engine delegates to the user's commandHandler, interprets the returned Effect, and handles persistence + side effects.

Table of Contents

Methods

create()  : Behavior
Create a Behavior that wraps event-sourced persistence around user-defined command and event handlers.

Methods

create()

Create a Behavior that wraps event-sourced persistence around user-defined command and event handlers.

public static create(PersistenceId $persistenceId, S $emptyState, callable(S, ActorContext, object): Effect $commandHandler, callable(S, E): S $eventHandler, EventStore $eventStore[, SnapshotStore|null $snapshotStore = null ][, SnapshotStrategy|null $snapshotStrategy = null ][, RetentionPolicy|null $retentionPolicy = null ][, Ulid $writerId = new Ulid() ][, ReplayFilter|null $replayFilter = null ]) : Behavior
Parameters
$persistenceId : PersistenceId

Unique identity for this persistent entity

$emptyState : S

Initial empty state before any events

$commandHandler : callable(S, ActorContext, object): Effect

Processes commands, returns Effect

$eventHandler : callable(S, E): S

Applies events to state (pure function)

$eventStore : EventStore

Store for persisting and loading events

$snapshotStore : SnapshotStore|null = null

Optional store for snapshots

$snapshotStrategy : SnapshotStrategy|null = null

When to take snapshots (default: never)

$retentionPolicy : RetentionPolicy|null = null

Event/snapshot retention (default: keep all)

$writerId : Ulid = new Ulid()

Writer identity stamped on persisted events and snapshots

$replayFilter : ReplayFilter|null = null

Filter for detecting writer conflicts during recovery

Tags
template

S of object

template

E of object

Return values
Behavior

The behavior to use when spawning the actor


        
On this page

Search results