Jido.Bus.Adapter behaviour (Jido v1.1.0-rc)

View Source

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

Summary

Callbacks

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

Return a child spec defining all processes required by the signal store.

Delete a previously recorded snapshot for a given source

Append one or more signals to a stream atomically.

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

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

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

Create a transient subscription to a single signal stream.

Create a persistent subscription to an signal stream.

Unsubscribe an existing subscriber from signal notifications.

Delete an existing subscription.

Types

application()

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

bus()

@type bus() :: map()

config()

@type config() :: Keyword.t()

error()

@type error() :: term()

expected_version()

@type expected_version() ::
  :any_version | :no_stream | :stream_exists | non_neg_integer()

source_id()

@type source_id() :: String.t()

start_from()

@type start_from() :: :origin | :current | integer()

stream_id()

@type stream_id() :: String.t()

subscriber()

@type subscriber() :: pid()

subscription()

@type subscription() :: any()

subscription_name()

@type subscription_name() :: String.t()

Callbacks

ack(bus, pid, t)

@callback ack(bus(), pid(), Jido.Bus.RecordedSignal.t()) :: :ok

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

child_spec(application, config)

@callback child_spec(application(), config()) ::
  {:ok, [:supervisor.child_spec() | {module(), term()} | module()], bus()}

Return a child spec defining all processes required by the signal store.

delete_snapshot(bus, source_id)

@callback delete_snapshot(bus(), source_id()) :: :ok | {:error, error()}

Delete a previously recorded snapshot for a given source

publish(bus, stream_id, expected_version, signals, opts)

@callback publish(
  bus(),
  stream_id(),
  expected_version(),
  signals :: [Jido.Bus.Signal.t()],
  opts :: Keyword.t()
) :: :ok | {:error, :wrong_expected_version} | {:error, error()}

Append one or more signals to a stream atomically.

read_snapshot(bus, source_id)

@callback read_snapshot(bus(), source_id()) ::
  {:ok, Jido.Bus.Snapshot.t()} | {:error, :snapshot_not_found}

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

record_snapshot(bus, t)

@callback record_snapshot(bus(), Jido.Bus.Snapshot.t()) :: :ok | {:error, error()}

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

replay(bus, stream_id, start_version, read_batch_size)

@callback replay(
  bus(),
  stream_id(),
  start_version :: non_neg_integer(),
  read_batch_size :: non_neg_integer()
) :: Enumerable.t() | {:error, :stream_not_found} | {:error, error()}

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

subscribe(bus, arg2)

@callback subscribe(bus(), stream_id() | :all) :: :ok | {:error, error()}

Create a transient subscription to a single signal stream.

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

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

subscribe_persistent(bus, arg2, subscription_name, subscriber, start_from, opts)

@callback subscribe_persistent(
  bus(),
  stream_id() | :all,
  subscription_name(),
  subscriber(),
  start_from(),
  opts :: Keyword.t()
) ::
  {:ok, subscription()}
  | {:error, :subscription_already_exists}
  | {:error, error()}

Create a persistent subscription to an signal stream.

unsubscribe(bus, subscription)

@callback unsubscribe(bus(), subscription()) :: :ok

Unsubscribe an existing subscriber from signal notifications.

This should not delete the subscription.

unsubscribe(bus, arg2, subscription_name)

@callback unsubscribe(
  bus(),
  stream_id() | :all,
  subscription_name()
) :: :ok | {:error, :subscription_not_found} | {:error, error()}

Delete an existing subscription.