The entrypoint for managing PGMQ notification subscriptions.
For general information about notification subscriptions, see
Postgrex.Notifications.
For more information about PGMQ notifications, see Notifications.
Summary
Functions
Starts a PGMQ notification listener linked to the current process.
Subscribes the current process to notifications for the given queue.
Unsubscribes the current process from notifications associated with the given listener reference.
Types
@type channel() :: String.t()
A notification channel name.
@type listener() :: GenServer.server()
A listener process.
@type subscription() :: reference()
A subscription reference.
Functions
@spec start_link(keyword()) :: {:ok, pid()} | {:error, Postgrex.Error.t() | term()}
Starts a PGMQ notification listener linked to the current process.
Connection Usage
Each notification listener uses its own Postgres connection outside of any
Ecto.Repo connection pools. Therefore, in most cases, it's preferable to
start a single listener that subscribes to multiple channels instead of
starting a single listener per channel.
Options
For information about supported options, see
Postgrex.Notifications.start_link/1.
Examples
Notifications.start_link([name: MyApp.Notifications | Repo.config()])
@spec subscribe(listener(), EctoPGMQ.Queue.name(), keyword()) :: {:ok | :eventually, subscription(), channel()}
Subscribes the current process to notifications for the given queue.
Notifications will manifest as messages with the following shape where
listener_pid is the pid/0 of the listener/0:
{:notification, listener_pid, subscription, channel, ""}Options
For information about supported options, see
Postgrex.Notifications.listen/3.
Examples
Notifications.subscribe(MyApp.Notifications, "my_queue")
@spec unsubscribe(listener(), subscription(), keyword()) :: :ok | :error
Unsubscribes the current process from notifications associated with the given listener reference.
Options
For information about supported options, see
Postgrex.Notifications.unlisten/3.
Examples
Notifications.unsubscribe(MyApp.Notifications, my_subscription)