ExESDB.GatewayAPI (ex_esdb v0.0.11-alpha)

Though the GatewayAPI GenServer is started on each node in the cluster, it acts as a simple high-availability proxy and load balancer for the GatewayWorker processes in the cluster.

Summary

Functions

Acknowledge receipt of an event by a subscriber to persistent subscription.

Append events to a stream. ## Parameters

Returns a specification to start this module under a supervisor.

Gets a list of all gateway worker pids.

Get events from a stream, staring from a given version, in a given direction.

Get all streams from the store. ## Parameters

Get the subscriptions for a store.

Get the version of a stream.

Callback implementation for GenServer.init/1.

Gets a random pid of a gateway worker in the cluster.

Types

error()

@type error() :: term()

selector_type()

@type selector_type() :: String.t() | map()

store()

@type store() :: atom()

stream()

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

subscription_name()

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

subscription_type()

@type subscription_type() ::
  :by_stream | :by_event_type | :by_event_pattern | :by_event_payload

Functions

ack_event(store, subscription_name, subscriber_pid, event)

@spec ack_event(
  store :: atom(),
  subscription_name :: String.t(),
  subscriber_pid :: pid(),
  event :: map()
) :: :ok | {:error, term()}

Acknowledge receipt of an event by a subscriber to persistent subscription.

append_events(store, stream_id, events)

@spec append_events(
  store :: atom(),
  stream_id :: stream(),
  events :: list()
) :: {:ok, integer()} | {:error, term()}

Append events to a stream. ## Parameters

  • store: the id of the store
  • stream_id: the id of the stream
  • events: the events to append

    Returns

    where new_version is the new version of the stream {:error, reason} if there was an error

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

gateway_worker_pids()

@spec gateway_worker_pids() :: list()

Gets a list of all gateway worker pids.

get_events(store, stream_id, start_version, count, direction \\ :forward)

@spec get_events(
  store :: atom(),
  stream_id :: stream(),
  start_version :: integer(),
  count :: integer(),
  direction :: :forward | :backward
) :: {:ok, list()} | {:error, term()}

Get events from a stream, staring from a given version, in a given direction.

get_streams(store)

@spec get_streams(store :: atom()) :: {:ok, list()} | {:error, term()}

Get all streams from the store. ## Parameters

- store: the id of the store

## Returns

- a list of all streams in the store

get_subscriptions(store)

@spec get_subscriptions(store :: atom()) :: {:ok, list()} | {:error, term()}

Get the subscriptions for a store.

get_version(store, stream)

@spec get_version(
  store :: atom(),
  stream :: stream()
) :: {:ok, integer()} | {:error, term()}

Get the version of a stream.

init(opts)

Callback implementation for GenServer.init/1.

random_gateway_worker()

@spec random_gateway_worker() :: pid()

Gets a random pid of a gateway worker in the cluster.

remove_subscription(store, type, selector, subscription_name \\ "transient")

@spec remove_subscription(
  store :: any(),
  type :: subscription_type(),
  selector :: selector_type(),
  subscription_name :: subscription_name()
) :: :ok | {:error, error()}

Remove a permanent or transient subscription.

save_subscription(store, type, selector, subscription_name \\ "transient", start_from \\ 0, subscriber \\ nil)

@spec save_subscription(
  store :: store(),
  type :: subscription_type(),
  selector :: selector_type(),
  subscription_name :: subscription_name(),
  start_from :: integer(),
  subscriber :: pid() | nil
) :: :ok | {:error, error()}

Add a permanent or transient subscription.

start_link(opts)