Commanded v0.16.0 Commanded.EventStore behaviour View Source

Defines the behaviour to be implemented by an event store adapter to be used by Commanded.

Link to this section Summary

Functions

Acknowledge receipt and successful processing of the given event received from a subscription to an event stream

Append one or more events to a stream atomically

Delete a previously recorded snapshop for a given source

Get the configured event store adapter

Read a snapshot, if available, for a given source

Record a snapshot of the data and metadata for a given source

Streams events from the given stream, in the order in which they were originally written

Create a transient subscription to a single event stream

Create a persistent subscription to all event streams

Unsubscribe an existing subscriber from all event notifications

Callbacks

Acknowledge receipt and successful processing of the given event received from a subscription to an event stream

Append one or more events to a stream atomically

Delete a previously recorded snapshop for a given source

Read a snapshot, if available, for a given source

Record a snapshot of the data and metadata for a given source

Streams events from the given stream, in the order in which they were originally written

Create a transient subscription to a single event stream

Create a persistent subscription to all event streams

Unsubscribe an existing subscriber from all event notifications

Link to this section Types

Link to this type source_uuid() View Source
source_uuid() :: String.t()
Link to this type start_from() View Source
start_from() :: :origin | :current | integer()
Link to this type stream_uuid() View Source
stream_uuid() :: String.t()
Link to this type stream_version() View Source
stream_version() :: integer()
Link to this type subscription_name() View Source
subscription_name() :: String.t()

Link to this section Functions

Acknowledge receipt and successful processing of the given event received from a subscription to an event stream.

Link to this function append_to_stream(stream_uuid, expected_version, events) View Source
append_to_stream(
  stream_uuid(),
  expected_version :: non_neg_integer(),
  events :: [Commanded.EventStore.EventData.t()]
) ::
  {:ok, stream_version()}
  | {:error, :wrong_expected_version}
  | {:error, reason()}

Append one or more events to a stream atomically.

Link to this function delete_snapshot(source_uuid) View Source
delete_snapshot(source_uuid()) :: :ok | {:error, reason()}

Delete a previously recorded snapshop for a given source

Get the configured event store adapter

Link to this function read_snapshot(source_uuid) View Source
read_snapshot(source_uuid()) ::
  {:ok, snapshot()} | {:error, :snapshot_not_found}

Read a snapshot, if available, for a given source.

Link to this function record_snapshot(snapshot) View Source
record_snapshot(snapshot()) :: :ok | {:error, reason()}

Record a snapshot of the data and metadata for a given source

Link to this function stream_forward(stream_uuid, start_version \\ 0, read_batch_size \\ 1000) View Source
stream_forward(
  stream_uuid(),
  start_version :: non_neg_integer(),
  read_batch_size :: non_neg_integer()
) :: Enumerable.t() | {:error, :stream_not_found} | {:error, reason()}

Streams events from the given stream, in the order in which they were originally written.

Link to this function subscribe(stream_uuid) View Source
subscribe(stream_uuid()) :: :ok | {:error, reason()}

Create a transient subscription to a single event stream.

Link to this function subscribe_to_all_streams(subscription_name, subscriber, start_from) View Source
subscribe_to_all_streams(
  subscription_name(),
  subscriber :: pid(),
  start_from()
) ::
  {:ok, subscription :: pid()}
  | {:error, :subscription_already_exists}
  | {:error, reason()}

Create a persistent subscription to all event streams.

Link to this function unsubscribe_from_all_streams(subscription_name) View Source
unsubscribe_from_all_streams(subscription_name()) :: :ok

Unsubscribe an existing subscriber from all event notifications.

Link to this section Callbacks

Acknowledge receipt and successful processing of the given event received from a subscription to an event stream.

Link to this callback append_to_stream(stream_uuid, expected_version, events) View Source
append_to_stream(
  stream_uuid(),
  expected_version :: non_neg_integer(),
  events :: [Commanded.EventStore.EventData.t()]
) ::
  {:ok, stream_version()}
  | {:error, :wrong_expected_version}
  | {:error, reason()}

Append one or more events to a stream atomically.

Link to this callback delete_snapshot(source_uuid) View Source
delete_snapshot(source_uuid()) :: :ok | {:error, reason()}

Delete a previously recorded snapshop for a given source

Link to this callback read_snapshot(source_uuid) View Source
read_snapshot(source_uuid()) ::
  {:ok, snapshot()} | {:error, :snapshot_not_found}

Read a snapshot, if available, for a given source.

Link to this callback record_snapshot(snapshot) View Source
record_snapshot(snapshot()) :: :ok | {:error, reason()}

Record a snapshot of the data and metadata for a given source

Link to this callback stream_forward(stream_uuid, start_version, read_batch_size) View Source
stream_forward(
  stream_uuid(),
  start_version :: non_neg_integer(),
  read_batch_size :: non_neg_integer()
) :: Enumerable.t() | {:error, :stream_not_found} | {:error, reason()}

Streams events from the given stream, in the order in which they were originally written.

Link to this callback subscribe(stream_uuid) View Source
subscribe(stream_uuid()) :: :ok | {:error, reason()}

Create a transient subscription to a single event stream.

The event store will publish any events appended to the given stream to the subscriber process as an {:events, events} message.

The subscriber does not need to acknowledge receipt of the events.

Link to this callback subscribe_to_all_streams(subscription_name, subscriber, start_from) View Source
subscribe_to_all_streams(
  subscription_name(),
  subscriber :: pid(),
  start_from()
) ::
  {:ok, subscription :: pid()}
  | {:error, :subscription_already_exists}
  | {:error, reason()}

Create a persistent subscription to all event streams.

The event store will remember the subscribers last acknowledged event. Restarting the named subscription will resume from the next event following the last seen.

Once subscribed, the subscriber process should be sent a {:subscribed, subscription} message to allow it to defer initialisation until the subscription has started.

The subscriber process will be sent all events persisted to any stream. It will receive a {:events, events} message for each batch of events persisted for a single aggregate.

The subscriber must ack each received, and successfully processed event, using Commanded.EventStore.ack_event/2.

Link to this callback unsubscribe_from_all_streams(subscription_name) View Source
unsubscribe_from_all_streams(subscription_name()) :: :ok

Unsubscribe an existing subscriber from all event notifications.