Commanded.EventStore (Commanded v1.3.1) View Source

Use the event store configured for a Commanded application.

Link to this section Summary

Functions

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

Get the configured event store adapter for the given application.

Append one or more events to a stream atomically.

Delete a previously recorded snapshot 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.

Unsubscribe an existing subscriber from event notifications.

Link to this section Types

Specs

application() :: Commanded.Application.t()

Specs

config() :: Keyword.t()

Link to this section Functions

Link to this function

ack_event(application, subscription, event)

View Source

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

Link to this function

adapter(application, config)

View Source

Specs

adapter(application(), config()) :: {module(), config()}

Get the configured event store adapter for the given application.

Link to this function

append_to_stream(application, stream_uuid, expected_version, events)

View Source

Append one or more events to a stream atomically.

Link to this function

delete_snapshot(application, source_uuid)

View Source

Delete a previously recorded snapshot for a given source

Link to this function

delete_subscription(application, subscribe_to, handler_name)

View Source

Delete an existing subscription.

Example

:ok = Commanded.EventStore.delete_subscription(MyApp, :all, "Example")
Link to this function

read_snapshot(application, source_uuid)

View Source

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

Link to this function

record_snapshot(application, snapshot)

View Source

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

Link to this function

stream_forward(application, stream_uuid, start_version \\ 0, read_batch_size \\ 1000)

View Source

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

Link to this function

subscribe(application, stream_uuid)

View Source

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 function

subscribe_to(application, stream_uuid, subscription_name, subscriber, start_from, options \\ [])

View Source

Create a persistent subscription to an event stream.

To subscribe to all events appended to any stream use :all as the stream when subscribing.

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/3.

Examples

Subscribe to all streams:

{:ok, subscription} =
  Commanded.EventStore.subscribe_to(MyApp, :all, "Example", self(), :current)

Subscribe to a single stream:

{:ok, subscription} =
  Commanded.EventStore.subscribe_to(MyApp, "stream1", "Example", self(), :origin)
Link to this function

unsubscribe(application, subscription)

View Source

Unsubscribe an existing subscriber from event notifications.

This will not delete the subscription.

Example

:ok = Commanded.EventStore.unsubscribe(MyApp, subscription)