evoq_aggregate behaviour (evoq v1.5.0)
View SourceAggregate behavior and GenServer implementation.
Aggregates are the consistency boundary in event sourcing. Each aggregate: - Has a unique stream ID - Processes commands via execute/2 callback - Applies events via apply/2 callback - Supports snapshots for fast recovery - Has configurable lifespan (TTL, hibernate, passivate)
Callbacks
Required: - init(AggregateId) -> {ok, State} - execute(State, Command) -> {ok, [Event]} | {error, Reason} - apply(State, Event) -> NewState
Optional: - snapshot(State) -> SnapshotData - from_snapshot(SnapshotData) -> State
Summary
Functions
Execute a command against an aggregate.
Get the current state of an aggregate (for debugging).
Get the current version of an aggregate.
Start an aggregate process (uses env store_id).
Start an aggregate process with explicit store_id.
Callbacks
Functions
-spec execute_command(pid(), #evoq_command{command_id :: binary() | undefined, command_type :: atom() | undefined, aggregate_type :: atom() | undefined, aggregate_id :: binary() | undefined, payload :: map(), metadata :: map(), causation_id :: binary() | undefined, correlation_id :: binary() | undefined, idempotency_key :: binary() | undefined}) -> {ok, non_neg_integer(), [map()]} | {error, term()}.
Execute a command against an aggregate.
Get the current state of an aggregate (for debugging).
-spec get_version(pid()) -> {ok, non_neg_integer()}.
Get the current version of an aggregate.
Start an aggregate process (uses env store_id).
Start an aggregate process with explicit store_id.