Yggdrasil v5.0.0 Yggdrasil.Backend behaviour View Source
Backend behaviour that defines how to subscribe, unsubscribe and publish as well as send messages of connection and disconnection to subscribers.
By default, the implementation uses Phoenix.PubSub
as backend.
Backend alias
When defining backends it is possible to define aliases for the module as follows:
defmodule Yggdrasil.Backend.MyBackend do
use Yggdrasil.Backend, name: :my_backend
(... behaviour implementation ...)
end
And adding the following to our application supervision tree:
Supervisor.start_link([
{Yggdrasil.Backend.MyBackend, []}
...
])
This will allow you to use the following as a Channel
to subscribe and
publish:
%Channel{name: "my_channel", backend: :my_backend}
Link to this section Summary
Functions
Macro for using Yggdrasil.Backend
.
Generic connected message sender to a channel
. Optionally receives
the pid
of the specific subscriber.
Generic disconnected message sender to a channel
. Optionally receives
the pid
of the specific subscriber.
Generic publish message
in a channel
with some optional metadata
.
Generic subscription in a channel
.
Transforms name of the channel
to a binary
.
Generic unsubscriptions in a channel
.
Callbacks
Callback to publish the connected message in the channel
. Receives a pid
in case the message shouldn't be broadcasted.
Callback to publish the disconnected message in the channel
. Receives a
pid
in case the message shouldn't be broadcasted.
Callback to publish a message
in a channel
with some metadata
.
Callback to define the subscription method. Receives the channel
.
Callback to define the unsubscription method. Receives the channel
.
Link to this section Functions
__using__(options) View Source (macro)
Macro for using Yggdrasil.Backend
.
The following are the available options:
:name
- Name of the backend. Must be an atom.
connected(channel, pid \\ nil)
View Source
connected(Yggdrasil.Channel.t(), nil | pid()) :: :ok | {:error, term()}
connected(Yggdrasil.Channel.t(), nil | pid()) :: :ok | {:error, term()}
Generic connected message sender to a channel
. Optionally receives
the pid
of the specific subscriber.
disconnected(channel, pid \\ nil)
View Source
disconnected(Yggdrasil.Channel.t(), nil | pid()) :: :ok | {:error, term()}
disconnected(Yggdrasil.Channel.t(), nil | pid()) :: :ok | {:error, term()}
Generic disconnected message sender to a channel
. Optionally receives
the pid
of the specific subscriber.
publish(channel, message, metadata \\ nil)
View Source
publish(Yggdrasil.Channel.t(), term(), term()) :: :ok | {:error, term()}
publish(Yggdrasil.Channel.t(), term(), term()) :: :ok | {:error, term()}
Generic publish message
in a channel
with some optional metadata
.
subscribe(channel)
View Source
subscribe(Yggdrasil.Channel.t()) :: :ok | {:error, term()}
subscribe(Yggdrasil.Channel.t()) :: :ok | {:error, term()}
Generic subscription in a channel
.
transform_name(channel)
View Source
transform_name(Yggdrasil.Channel.t()) :: binary()
transform_name(Yggdrasil.Channel.t()) :: binary()
Transforms name of the channel
to a binary
.
unsubscribe(channel)
View Source
unsubscribe(Yggdrasil.Channel.t()) :: :ok | {:error, term()}
unsubscribe(Yggdrasil.Channel.t()) :: :ok | {:error, term()}
Generic unsubscriptions in a channel
.
Link to this section Callbacks
connected(channel, pid)
View Source
connected(channel :: Yggdrasil.Channel.t(), pid :: atom() | pid()) ::
:ok | {:error, term()}
connected(channel :: Yggdrasil.Channel.t(), pid :: atom() | pid()) :: :ok | {:error, term()}
Callback to publish the connected message in the channel
. Receives a pid
in case the message shouldn't be broadcasted.
disconnected(channel, pid)
View Source
disconnected(channel :: Yggdrasil.Channel.t(), pid :: atom() | pid()) ::
:ok | {:error, term()}
disconnected(channel :: Yggdrasil.Channel.t(), pid :: atom() | pid()) :: :ok | {:error, term()}
Callback to publish the disconnected message in the channel
. Receives a
pid
in case the message shouldn't be broadcasted.
publish(channel, message, metadata)
View Source
publish(channel :: Yggdrasil.Channel.t(), message :: term(), metadata :: term()) ::
:ok | {:error, term()}
publish(channel :: Yggdrasil.Channel.t(), message :: term(), metadata :: term()) :: :ok | {:error, term()}
Callback to publish a message
in a channel
with some metadata
.
subscribe(channel)
View Source
subscribe(channel :: Yggdrasil.Channel.t()) :: :ok | {:error, term()}
subscribe(channel :: Yggdrasil.Channel.t()) :: :ok | {:error, term()}
Callback to define the subscription method. Receives the channel
.
unsubscribe(channel)
View Source
unsubscribe(channel :: Yggdrasil.Channel.t()) :: :ok | {:error, term()}
unsubscribe(channel :: Yggdrasil.Channel.t()) :: :ok | {:error, term()}
Callback to define the unsubscription method. Receives the channel
.