Pubsub in a phoenix app under umbrella

I would like to add this here for future reference:

I ran into this problem while going thru Programming Phoenix 1.4 book, Chapter 11, section Extracting Rumbl and RumblWeb, page 238 very bottom.

The error encountered is this (adding to be google-able):

** (Mix) Could not start application rumbl_web: RumblWeb.Application.start(:normal, []) returned an error: shutdown: failed to start child: RumblWeb.Presence
    ** (EXIT) shutdown: failed to start child: Phoenix.Presence.Tracker
        ** (EXIT) shutdown: failed to start child: RumblWeb.Presence_shard0
            ** (EXIT) an exception was raised:
                ** (ArgumentError) unknown registry: RumblWeb.PubSub
...

The exact solution based on this thread seems to be editing /rumbl_umbrella/apps/rumbl/lib/rumbl/application.ex so that the children there are:

children = [
      Rumbl.Repo,
      {Phoenix.PubSub, name: Rumbl.PubSub}, # added missing piece
    ]

The file /rumbl_umbrella/config/config.exs says that the pub_sub server for rumbl_web is this

config :rumbl_web, RumblWeb.Endpoint,
  ...
  pubsub_server: Rumbl.PubSub,
  ...

so then I also changed /rumbl_umbrella/apps/rumbl_web/lib/rumbl_web/channels/presence.ex so that it starts with

use Phoenix.Presence,
    otp_app: :rumbl_web,
    pubsub_server: Rumbl.PubSub

Upon all these changes it seems to work (despite having some “connection refused” messages in console). Long story short, seems like one needs Rumbl.PubSub consistently everywhere.

Hope this helps somebody.

11 Likes