ExMessageDB v0.1.0 ExMessageDB.MessageStore behaviour View Source

Defines a message store.

When used, the message store expects the :repo option. For example:

defmodule MyApp.MessageStore do
  use ExMessageDB.MessageStore, repo: MyApp.Repo
end

Link to this section Summary

Callbacks

Retrieve messages from a category of streams, optionally specifying the starting position, the number of messages to retrieve.

Returns the row from the messages table that corresponds to the highest position number in the stream.

Retrieve messages from a single stream, optionally specifying the starting position, the number of messages to retrieve.

Returns the version number of the message store database.

Write a JSON-formatted message to a named stream, optionally specifying JSON-formatted metadata and an expected version number.

Link to this section Callbacks

Link to this callback

get_category_messages(category_name, position, batch_size)

View Source (since 0.1.0)

Specs

get_category_messages(
  category_name :: String.t(),
  position :: non_neg_integer() | nil,
  batch_size :: non_neg_integer() | -1 | nil
) ::
  [] | [%{message: ExMessageDB.Message.t()}] | {:error, message :: String.t()}

Retrieve messages from a category of streams, optionally specifying the starting position, the number of messages to retrieve.

Link to this callback

get_last_stream_message(stream_name)

View Source (since 0.1.0)

Specs

get_last_stream_message(stream_name :: String.t()) ::
  nil | %{message: ExMessageDB.Message.t()}

Returns the row from the messages table that corresponds to the highest position number in the stream.

Link to this callback

get_stream_messages(stream_name, position, batch_size)

View Source (since 0.1.0)

Specs

get_stream_messages(
  stream_name :: String.t(),
  position :: non_neg_integer() | nil,
  batch_size :: non_neg_integer() | -1 | nil
) ::
  [] | [%{message: ExMessageDB.Message.t()}] | {:error, message :: String.t()}

Retrieve messages from a single stream, optionally specifying the starting position, the number of messages to retrieve.

Link to this callback

message_store_version()

View Source (since 0.1.0)

Specs

message_store_version() :: string_version :: String.t()

Returns the version number of the message store database.

Link to this callback

write_message(%{})

View Source (since 0.1.0)

Specs

write_message(%{
  id: id :: String.t(),
  stream_name: stream_name :: String.t(),
  embedded_data: Ecto.Schema.embedded_schema()
}) :: {:ok, position :: non_neg_integer()} | {:error, message :: String.t()}
write_message(%{
  id: id :: String.t(),
  stream_name: stream_name :: String.t(),
  type: type :: String.t(),
  data: map()
}) :: {:ok, position :: non_neg_integer()} | {:error, message :: String.t()}

Write a JSON-formatted message to a named stream, optionally specifying JSON-formatted metadata and an expected version number.

Returns the position of the message written.

Link to this callback

write_message(id, stream_name, embedded_data, metadata, expected_version)

View Source (since 0.1.0)

Specs

write_message(
  id :: String.t(),
  stream_name :: String.t(),
  embedded_data :: Ecto.Schema.embedded_schema(),
  metadata :: map() | nil,
  expected_version :: non_neg_integer() | -1 | nil
) :: {:ok, position :: non_neg_integer()} | {:error, message :: String.t()}

See write_message/1 for more information.