EctoPGMQ.Notifications (ecto_pgmq v2.0.0)

Copy Markdown View Source

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

Types

A notification channel name.

A listener process.

A subscription reference.

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

channel()

@type channel() :: String.t()

A notification channel name.

listener()

@type listener() :: GenServer.server()

A listener process.

subscription()

@type subscription() :: reference()

A subscription reference.

Functions

start_link(opts)

@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()])

subscribe(listener, queue, opts \\ [])

@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")

unsubscribe(listener, subscription, opts \\ [])

@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)