mule/notifiers/pg

A process-groups notifier over Distributed Erlang — a port of Oban.Notifiers.PG (notifiers/pg.ex). Scales better than the Postgres notifier and needs no database round-trip, but lacks its transactional guarantees and requires a functional Distributed Erlang cluster (on a single unclustered node it degrades gracefully to a local-only notifier — useful for tests, pointless in production).

Every PG notifier in the cluster joins one pg group per namespace; notify sends the notification to EVERY member (its own actor included), and each member relays to its local subscribers. Like Elixir, the default namespace is shared (“public”, the port’s fixed prefix), so ALL instances in the cluster hear each other — pass Namespace to isolate a cluster of instances without renaming them.

Divergence (parity §9): members exchange the TYPED Notification term directly rather than Elixir’s JSON-ish maps — every node must run this library (Elixir-interop remains out of scope), and in return there is no codec to drift. The namespace is a String where Elixir allows any term.

Types

pub type Message {
  Listen(
    channel: notifier.Channel,
    subscriber: process.Subject(notifier.Notification),
  )
  Unlisten(
    channel: notifier.Channel,
    subscriber: process.Subject(notifier.Notification),
  )
  Notify(notification: notifier.Notification)
  Relay(notification: notifier.Notification)
  SubscriberDown(down: process.Down)
}

Constructors

pub type State {
  State(
    namespace: String,
    subscribers: dict.Dict(
      notifier.Channel,
      set.Set(process.Subject(notifier.Notification)),
    ),
    monitors: dict.Dict(process.Pid, process.Monitor),
  )
}

Constructors

Values

pub fn child(
  name name: process.Name(Message),
) -> supervision.ChildSpecification(Nil)

A supervisor child spec that starts this notifier registered under name in the default namespace. Pair with new(process.named_subject(name)) for the MuleSpec.

pub fn child_in_namespace(
  name name: process.Name(Message),
  namespace namespace: String,
) -> supervision.ChildSpecification(Nil)

child with an explicit namespace, to isolate a set of instances within a cluster (pg.ex’s namespace option).

pub const default_namespace: String

All instances sharing a namespace notify each other; the default groups the whole cluster, like Elixir’s prefix-derived default.

pub fn start(
  namespace namespace: String,
) -> Result(
  actor.Started(process.Subject(Message)),
  actor.StartError,
)
pub fn start_named(
  name name: process.Name(Message),
  namespace namespace: String,
) -> Result(
  actor.Started(process.Subject(Message)),
  actor.StartError,
)
Search Document