Helios v0.2.2 Helios.Aggregate behaviour View Source

Aggregate behaviour.

Once implemented add command mapping to router Helios.Router.

Link to this section Summary

Callbacks

Applies single event to aggregate when replied or after handle_exec/3 is executed

Optional cllback, when implemented it should treansform offered snapshot into aggregate model

Handles execution of the command once command is handed from router to Helios.Aggregate.Server

Constructs new instance of aggregate struct. Override to set defaults or if your struct is defined in different module

Returns unique identifier for stream to which events will be persisted

Optional callback, when implmented it should return snapshot of given aggregate

Link to this section Types

Link to this type aggregate() View Source
aggregate() :: struct()
Link to this type aggregate_id() View Source
aggregate_id() :: String.t()

The unique aggregate id.

Link to this type from() View Source
from() :: {pid(), tag :: term()}
Link to this type init_args() View Source
init_args() :: [otp_app: atom(), id: aggregate_id()]

Link to this section Functions

Link to this section Callbacks

Link to this callback apply_event(event, aggregate) View Source
apply_event(event :: any(), aggregate()) :: aggregate() | no_return()

Applies single event to aggregate when replied or after handle_exec/3 is executed.

Must return {:ok, state} if event is aplied or raise an error if failed. Note that events should not be validated here, they must be respected since handle_execute/3 generated event and already validate it. Also, error has to bi risen in for some odd reason event cannot be applied to aggregate.

Link to this callback from_snapshot(snapshot_offer, aggregate) View Source (optional)
from_snapshot(snapshot_offer :: SnapshotOffer.t(), aggregate()) ::
  {:ok, aggregate()} | {:skip, aggregate()}

Optional cllback, when implemented it should treansform offered snapshot into aggregate model.

Return {:ok, aggregate} if snapshot is applied to aggregate, or {:ignored, aggregate} if you want ignore snapshot and apply all events from beginning of the aggregate stream

Handles execution of the command once command is handed from router to Helios.Aggregate.Server.

Link to this callback new(args) View Source
new(args :: init_args()) :: {:ok, aggregate()} | {:stop, term()} | :ignore

Constructs new instance of aggregate struct. Override to set defaults or if your struct is defined in different module.

Link to this callback persistance_id(id) View Source
persistance_id(id :: term()) :: String.t()

Returns unique identifier for stream to which events will be persisted.

This persistance id will be used while persisting events emitted by aggregate into its own stream of the events.

Link to this callback to_snapshot(aggregate) View Source (optional)
to_snapshot(aggregate()) :: any()

Optional callback, when implmented it should return snapshot of given aggregate.

When snapshot is stored it should record among aggregate state, sequence number (or last_event_number) at which snapshot was taken.