Commanded v0.15.0 Commanded.Aggregates.Aggregate View Source

Aggregate is a GenServer process used to provide access to an instance of an event sourced aggregate. It allows execution of commands against an aggregate instance, and handles persistence of created events to the configured event store.

Concurrent commands sent to an aggregate instance are serialized and executed in the order received.

The Commanded.Commands.Router module will locate, or start, an aggregate instance when a command is dispatched. By default, an aggregate process will run indefinitely once started. Its lifespan may be controlled by using the Commanded.Aggregates.AggregateLifespan behaviour.

Link to this section Summary

Link to this section Functions

Link to this function execute(aggregate_module, aggregate_uuid, context, timeout \\ 5000) View Source

Execute the given command against the aggregate.

  • aggregate_module - the aggregate’s module (e.g. BankAccount).
  • aggregate_uuid - uniquely identifies an instance of the aggregate.
  • context - includes command execution arguments (see Commanded.Aggregates.ExecutionContext for details).
  • timeout - an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom :infinity to wait indefinitely. The default value is five seconds (5,000ms).

Return values

Returns {:ok, aggregate_version, events} on success, or {:error, reason} on failure.

  • aggregate_version - the updated version of the aggregate after executing the command.
  • events - events produced by the command, can be an empty list.
Link to this function start_link(aggregate_module, aggregate_uuid, opts \\ []) View Source