Spear.Client behaviour (Spear v0.8.0) View Source
A macro for defining a module which represents a connection to an EventStoreDB
Like an Ecto.Repo
or an Extreme
client, this macro allows you to call
functions on the module representing the connection instead of passing
the connection pid or name as an argument to functions in Spear
. This
can be useful for client connections central to a service. All callbacks
provided by this module are implemented on clients created with
use Spear.Client
.
This pattern can be useful for applications which depend on an EventStoreDB
connection similar to applications which depend on a (e.g.) PostgreSQL
connection via Ecto.Repo
. Writing clients as modules provides an
intuitive "is-a" interface (e.g. "MyEventStoreClient
is an EventStoreDB
client"). Since this module defines a complete behaviour for a client
module, mocking calls to the EventStoreDB is easy via a test dependency
like the wonderful Dashbit library Mox
.
If a service does not know which connections it may need until runtime, the
functions in Spear may be used with a connection processes spawned via
DynamicSupervisor.start_child/2
instead.
Configuration
The __using__/1
macro defined by this module takes an optional :otp_app
option. If provided, a helper clause for the start_link/1
callback will
be injected which will fetch configuration for the connection from
Application.get_env(otp_app, __MODULE__)
, if available.
Otherwise configuration for the connection may be passed through arguments
to start_link/1
.
Examples
defmodule MyEventStoreClient do
use Spear.Client, otp_app: :my_app
end
[MyEventStoreClient] |> Supervisor.start_link(strategy: :one_for_one)
iex> MyEventStoreClient.stream!(:all) |> Enum.take(1)
[%Spear.Event{}]
Link to this section Summary
Callbacks
A wrapper around Spear.ack/3
A wrapper around Spear.append/3
A wrapper around Spear.append/4
A wrapper around Spear.cancel_subscription/2
A wrapper around Spear.change_user_password/4
A wrapper around Spear.change_user_password/5
A wrapper around Spear.cluster_info/1
A wrapper around Spear.cluster_info/2
A wrapper around Spear.connect_to_persistent_subscription/4
A wrapper around Spear.connect_to_persistent_subscription/5
A wrapper around Spear.create_persistent_subscription/4
A wrapper around Spear.create_persistent_subscription/5
A wrapper around Spear.create_user/5
A wrapper around Spear.delete_persistent_subscription/3
A wrapper around Spear.delete_persistent_subscription/4
A wrapper around Spear.delete_stream/2
A wrapper around Spear.delete_stream/3
A wrapper around Spear.delete_user/2
A wrapper around Spear.delete_user/3
A wrapper around Spear.disable_user/2
A wrapper around Spear.disable_user/3
A wrapper around Spear.enable_user/2
A wrapper around Spear.enable_user/3
A wrapper around Spear.get_stream_metadata/2
A wrapper around Spear.get_stream_metadata/3
A wrapper around Spear.list_persistent_subscriptions/1
A wrapper around Spear.list_persistent_subscriptions/2
A wrapper around Spear.merge_indexes/1
A wrapper around Spear.merge_indexes/2
A wrapper around Spear.nack/3
A wrapper around Spear.nack/4
A wrapper around Spear.ping/1
A wrapper around Spear.ping/2
A wrapper around Spear.read_stream/2
A wrapper around Spear.read_stream/3
A wrapper around Spear.reset_user_password/3
A wrapper around Spear.resign_node/1
A wrapper around Spear.resign_node/2
A wrapper around Spear.set_global_acl/3
A wrapper around Spear.set_global_acl/4
A wrapper around Spear.set_node_priority/2
A wrapper around Spear.set_node_priority/3
A wrapper around Spear.set_stream_metadata/3
A wrapper around Spear.set_stream_metadata/4
A wrapper around Spear.shutdown/1
A wrapper around Spear.shutdown/2
Starts a client as part of a supervision tree.
A wrapper around Spear.start_scavenge/1
A wrapper around Spear.start_scavenge/2
A wrapper around Spear.stop_scavenge/2
A wrapper around Spear.stop_scavenge/3
A wrapper around Spear.stream!/2
A wrapper around Spear.stream!/3
A wrapper around Spear.subscribe/3
A wrapper around Spear.subscribe/4
A wrapper around Spear.update_persistent_subscription/4
A wrapper around Spear.update_persistent_subscription/5
A wrapper around Spear.update_user/5
A wrapper around Spear.user_details/3
A wrapper around Spear.user_details/3
Link to this section Callbacks
Specs
ack(subscription :: reference(), event_or_ids :: Spear.Event.t() | [String.t()]) :: :ok | {:error, any()}
A wrapper around Spear.ack/3
Specs
append(event_stream :: Enumerable.t(), stream_name :: String.t()) :: :ok | {:error, any()}
A wrapper around Spear.append/3
Specs
append( event_stream :: Enumerable.t(), stream_name :: String.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.append/4
Specs
A wrapper around Spear.cancel_subscription/2
cancel_subscription(subscription_reference, timeout)
View Source (since 0.1.0)Specs
A wrapper around Spear.cancel_subscription/3
change_user_password(login_name, current_password, new_password)
View Source (since 0.3.0)Specs
change_user_password( login_name :: String.t(), current_password :: String.t(), new_password :: String.t() ) :: :ok | {:error, any()}
A wrapper around Spear.change_user_password/4
change_user_password(login_name, current_password, new_password, opts)
View Source (since 0.3.0)Specs
change_user_password( login_name :: String.t(), current_password :: String.t(), new_password :: String.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.change_user_password/5
Specs
cluster_info() :: :ok | {:error, any()}
A wrapper around Spear.cluster_info/1
Specs
A wrapper around Spear.cluster_info/2
connect_to_persistent_subscription(subscriber, stream_name, group_name)
View Source (since 0.6.0)Specs
connect_to_persistent_subscription( subscriber :: pid() | GenServer.name(), stream_name :: String.t(), group_name :: String.t() ) :: {:ok, reference()} | {:error, any()}
A wrapper around Spear.connect_to_persistent_subscription/4
connect_to_persistent_subscription(subscriber, stream_name, group_name, opts)
View Source (since 0.6.0)Specs
connect_to_persistent_subscription( subscriber :: pid() | GenServer.name(), stream_name :: String.t(), group_name :: String.t(), opts :: Keyword.t() ) :: {:ok, reference()} | {:error, any()}
A wrapper around Spear.connect_to_persistent_subscription/5
create_persistent_subscription(stream_name, group_name, settings)
View Source (since 0.6.0)Specs
create_persistent_subscription( stream_name :: String.t(), group_name :: String.t(), settings :: Spear.PersistentSubscription.Settings.t() ) :: :ok | {:error, any()}
A wrapper around Spear.create_persistent_subscription/4
create_persistent_subscription(stream_name, group_name, settings, opts)
View Source (since 0.6.0)Specs
create_persistent_subscription( stream_name :: String.t(), group_name :: String.t(), settings :: Spear.PersistentSubscription.Settings.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.create_persistent_subscription/5
create_user(full_name, login_name, password, groups)
View Source (since 0.3.0)Specs
create_user( full_name :: String.t(), login_name :: String.t(), password :: String.t(), groups :: [String.t()] ) :: :ok | {:error, any()}
A wrapper around Spear.create_user/5
create_user(full_name, login_name, password, groups, opts)
View Source (since 0.3.0)Specs
create_user( full_name :: String.t(), login_name :: String.t(), password :: String.t(), groups :: [String.t()], opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.create_user/6
delete_persistent_subscription(stream_name, group_name)
View Source (since 0.6.0)Specs
delete_persistent_subscription( stream_name :: String.t(), group_name :: String.t() ) :: :ok | {:error, any()}
A wrapper around Spear.delete_persistent_subscription/3
delete_persistent_subscription(stream_name, group_name, opts)
View Source (since 0.6.0)Specs
delete_persistent_subscription( stream_name :: String.t(), group_name :: String.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.delete_persistent_subscription/4
Specs
A wrapper around Spear.delete_stream/2
Specs
A wrapper around Spear.delete_stream/3
Specs
A wrapper around Spear.delete_user/2
Specs
A wrapper around Spear.delete_user/3
Specs
A wrapper around Spear.disable_user/2
Specs
A wrapper around Spear.disable_user/3
Specs
A wrapper around Spear.enable_user/2
Specs
A wrapper around Spear.enable_user/3
Specs
A wrapper around Spear.get_stream_metadata/2
Specs
A wrapper around Spear.get_stream_metadata/3
Specs
list_persistent_subscriptions() :: {:ok, Enumerable.t()} | {:error, any()}
A wrapper around Spear.list_persistent_subscriptions/1
Specs
list_persistent_subscriptions(opts :: Keyword.t()) :: {:ok, Enumerable.t()} | {:error, any()}
A wrapper around Spear.list_persistent_subscriptions/2
Specs
merge_indexes() :: :ok | {:error, any()}
A wrapper around Spear.merge_indexes/1
Specs
A wrapper around Spear.merge_indexes/2
Specs
nack( subscription :: reference(), event_or_ids :: Spear.Event.t() | [String.t()] ) :: :ok | {:error, any()}
A wrapper around Spear.nack/3
Specs
nack( subscription :: reference(), event_or_ids :: Spear.Event.t() | [String.t()], opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.nack/4
Specs
ping() :: :pong | {:error, any()}
A wrapper around Spear.ping/1
Specs
A wrapper around Spear.ping/2
Specs
read_stream(stream_name :: String.t() | :all) :: {:ok, Enumerable.t()} | {:error, any()}
A wrapper around Spear.read_stream/2
Specs
read_stream(stream_name :: String.t() | :all, opts :: Keyword.t()) :: {:ok, Enumerable.t()} | {:error, any()}
A wrapper around Spear.read_stream/3
Specs
A wrapper around Spear.reset_user_password/3
Specs
reset_user_password( login_name :: String.t(), new_password :: String.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.reset_user_password/4
Specs
resign_node() :: :ok | {:error, any()}
A wrapper around Spear.resign_node/1
Specs
A wrapper around Spear.resign_node/2
Specs
restart_persistent_subscriptions() :: :ok | {:error, any()}
A wrapper around Spear.restart_persistent_subscriptions/1
Specs
A wrapper around Spear.restart_persistent_subscriptions/2
Specs
set_global_acl(user_acl :: Spear.Acl.t(), system_acl :: Spear.Acl.t()) :: :ok | {:error, any()}
A wrapper around Spear.set_global_acl/3
Specs
set_global_acl( user_acl :: Spear.Acl.t(), system_acl :: Spear.Acl.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.set_global_acl/4
Specs
A wrapper around Spear.set_node_priority/2
Specs
A wrapper around Spear.set_node_priority/3
Specs
set_stream_metadata(stream :: String.t(), metadata :: Spear.StreamMetadata.t()) :: :ok | {:error, any()}
A wrapper around Spear.set_stream_metadata/3
Specs
set_stream_metadata( stream :: String.t(), metadata :: Spear.StreamMetadata.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.set_stream_metadata/4
Specs
shutdown() :: :ok | {:error, any()}
A wrapper around Spear.shutdown/1
Specs
A wrapper around Spear.shutdown/2
Specs
start_link(args :: Keyword.t()) :: GenServer.on_start()
Starts a client as part of a supervision tree.
This function is defaulted to pull connection parameters from application
config or from the args
Examples
# lib/my_app/application.ex
[
{MyEventStoreClient, connection_string: "esdb://localhost:2113"},
..
]
|> Supervisor.start_link(strategy: :one_for_one)
Specs
start_scavenge() :: :ok | {:error, any()}
A wrapper around Spear.start_scavenge/1
Specs
A wrapper around Spear.start_scavenge/2
Specs
A wrapper around Spear.stop_scavenge/2
Specs
A wrapper around Spear.stop_scavenge/3
Specs
stream!(stream_name :: String.t() | :all) :: Enumerable.t()
A wrapper around Spear.stream!/2
Specs
stream!(stream_name :: String.t() | :all, opts :: Keyword.t()) :: Enumerable.t()
A wrapper around Spear.stream!/3
Specs
subscribe( subscriber :: pid() | GenServer.name(), stream_name :: String.t() | :all ) :: {:ok, reference()} | {:error, any()}
A wrapper around Spear.subscribe/3
Specs
subscribe( subscriber :: pid() | GenServer.name(), stream_name :: String.t() | :all, opts :: Keyword.t() ) :: {:ok, reference()} | {:error, any()}
A wrapper around Spear.subscribe/4
update_persistent_subscription(stream_name, group_name, settings)
View Source (since 0.6.0)Specs
update_persistent_subscription( stream_name :: String.t(), group_name :: String.t(), settings :: Spear.PersistentSubscription.Settings.t() ) :: :ok | {:error, any()}
A wrapper around Spear.update_persistent_subscription/4
update_persistent_subscription(stream_name, group_name, settings, opts)
View Source (since 0.6.0)Specs
update_persistent_subscription( stream_name :: String.t(), group_name :: String.t(), settings :: Spear.PersistentSubscription.Settings.t(), opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.update_persistent_subscription/5
update_user(full_name, login_name, password, groups)
View Source (since 0.3.0)Specs
update_user( full_name :: String.t(), login_name :: String.t(), password :: String.t(), groups :: [String.t()] ) :: :ok | {:error, any()}
A wrapper around Spear.update_user/5
update_user(full_name, login_name, password, groups, opts)
View Source (since 0.3.0)Specs
update_user( full_name :: String.t(), login_name :: String.t(), password :: String.t(), groups :: [String.t()], opts :: Keyword.t() ) :: :ok | {:error, any()}
A wrapper around Spear.update_user/6
Specs
A wrapper around Spear.user_details/3
Specs
A wrapper around Spear.user_details/3