Phoenix.PubSub parameters. When would the first argument be something different than App.PubSub?

Phoenix.PubSub.broadcast(App.PubSub, "message", {:text_stuff, text})

What is the significance of the first argument of broadcast and subscribe?
What is a scenario where the first argument would be something different other than App.PubSub ? In the docs this argument is described simply as “The name of the pubsub system”.

From my perspective this is just boilerplate and I would like to know a situation where it would change.

Thank you

Take a look at your application.ex. PubSub is started there and given a name. That‘s required wherever you interact with that system. You could have many separate pubsub systems with different names.

2 Likes

I often create a module with the same name as the PubSub and implement the PubSub functions with __MODULE__ as the first parameter.

As @LostKobrakai mentions, it is the name under which your Phoenix.PubSub process is registered.
This is YourApp.PubSub by convention. When you have multiple apps in a cluster, you start a Phoenix.PubSub in each app, with identical names, then all these instances talk to each other.
I recently wrote a small article about this on my blog.

Thanks for the blog post. I appreciate it.