ClusterHelper.Broadcast behaviour (ClusterHelper v1.0.0)

Copy Markdown View Source

Behaviour for cluster-wide messaging.

Implementations handle the mechanics of delivering messages to all nodes in a scope. The configured adapter is resolved via ClusterHelper.Adapter.

Built-in adapters

Custom adapters

defmodule MyApp.MyBroadcast do
  @behaviour ClusterHelper.Broadcast

  @impl true
  def start_scope(scope), do: ...
  @impl true
  def join(scope), do: ...
  @impl true
  def leave(scope), do: ...
  @impl true
  def broadcast(scope, message), do: ...
end

Then configure it:

config :cluster_helper, ClusterHelper.Adapter,
  broadcast: MyApp.MyBroadcast

Summary

Callbacks

Sends a message to every other member of the scope.

Joins the current process to the scope's group.

Leaves the current process from the scope's group.

Ensures the messaging scope is initialized.

Functions

Broadcasts a message (delegates to configured adapter).

Joins the current process (delegates to configured adapter).

Leaves the current process (delegates to configured adapter).

Ensures a scope is started (delegates to configured adapter).

Callbacks

broadcast(scope, message)

@callback broadcast(scope :: atom(), message :: term()) :: :ok

Sends a message to every other member of the scope.

join(scope)

@callback join(scope :: atom()) :: :ok

Joins the current process to the scope's group.

leave(scope)

@callback leave(scope :: atom()) :: :ok

Leaves the current process from the scope's group.

start_scope(scope)

@callback start_scope(scope :: atom()) :: :ok

Ensures the messaging scope is initialized.

Functions

broadcast(scope, message)

@spec broadcast(atom(), term()) :: :ok

Broadcasts a message (delegates to configured adapter).

join(scope)

@spec join(atom()) :: :ok

Joins the current process (delegates to configured adapter).

leave(scope)

@spec leave(atom()) :: :ok

Leaves the current process (delegates to configured adapter).

start_scope(scope)

@spec start_scope(atom()) :: :ok

Ensures a scope is started (delegates to configured adapter).