Yggdrasil for PostgreSQL v5.0.1 Yggdrasil.Publisher.Adapter.Postgres View Source

Yggdrasil publisher adapter for Postgres. The name of the channel must be a binary e.g:

Subscription to channel:

iex(1)> channel = [name: "pg_channel", adapter: :postgres]
iex(2)> Yggdrasil.subscribe(channel)
:ok
iex(3)> flush()
{:Y_CONNECTED, %Yggdrasil.Channel{name: "pg_channel", (...)}}

Publishing message:

iex(4)> Yggdrasil.publish(channel, "foo")
:ok

Subscriber receiving message:

iex(5)> flush()
{:Y_EVENT, %Yggdrasil.Channel{name: "pg_channel", (...)}, "foo"}

The subscriber can also unsubscribe from the channel:

iex(6)> Yggdrasil.unsubscribe(channel)
:ok
iex(7)> flush()
{:Y_DISCONNECTED, %Yggdrasil.Channel{name: "pg_channel", (...)}}

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Publishes a message in a channel using a publisher and optional and unused options.

Starts a Postgres publisher with a namespace. Additianally you can add GenServer options.

Stops a Postgres publisher. Optionally, receives a stop reason (defaults to :normal) and a timeout in milliseconds (defaults to :infinity).

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

publish(publisher, channel, message, options \\ [])

View Source
publish(GenServer.server(), Yggdrasil.Channel.t(), term(), Keyword.t()) ::
  :ok | {:error, term()}
publish(GenServer.name(), Yggdrasil.Channel.t(), term(), Keyword.t()) ::
  :ok | {:error, term()}

Publishes a message in a channel using a publisher and optional and unused options.

Link to this function

start_link(namespace, options \\ [])

View Source

Starts a Postgres publisher with a namespace. Additianally you can add GenServer options.

Link to this function

stop(publisher, reason \\ :normal, timeout \\ :infinity)

View Source
stop(GenServer.name(), term(), non_neg_integer() | :infinity) :: :ok

Stops a Postgres publisher. Optionally, receives a stop reason (defaults to :normal) and a timeout in milliseconds (defaults to :infinity).