Examples usage of Oban with Phoenix PubSub

Hi all :wave:

I looked at using oban_notifiers_phoenix for PubSub in Phoenix but neither the tests in the GitHub repo nor the documentation gives any examples of how to subscribe to these notifications.

I did search GitHub but couldn’t find any use of the package in the wild so to speak.

Wouldn’t it be terrific with examples setting out how to subscribe?

I would sure need some at least :see_no_evil: Or I’m just missing something fundamental regarding its intended use I guess.

Asking for a friend etc.

1 Like

Isn’t this what you are looking for?

test "broadcasting notifications to subscribers" do
  :ok = Notifier.listen(:signal)
  :ok = Notifier.notify(:signal, %{incoming: "message"})

  assert_receive {:notification, :signal, %{"incoming" => "message"}}
end

The first test shows how to listen to the notifier (aka subscribe) and how to send a signal.

2 Likes

Thanks :pray: So, I’m not missing out on any other way one should do it. This helps :slight_smile:

The oban_phoenix_pubsub package is only an adapter rather than a module you’d call directly. There’s an example of how to listen, notify, and receive notifications in the Oban.Notifier module: Oban.Notifier — Oban v2.18.3.

The listen/2 and notify/2 functions also have some examples.

3 Likes