blset

blset

Pubsub in a phoenix app under umbrella

When creating a new project with

mix phx.new proj --umbrella

the phoenix_pubsub dependency is placed in the mix.exs of the proj app and not under the proj_web app.

but that seems against app isolation. since the proj app, in the idea, should have no dependency on phoenix nor any web consideration.

more over when manually placing the phoenix pub_sub in the proj_web mix.exs and adjusting the config of the umbrella config, it does not work with message

unknown registry: ProjWeb.PubSub

how to make i work with phoenix_pubsub under the web app ?

Marked As Solved

LostKobrakai

LostKobrakai

Here’s the place it’s started for a single project phoenix app:

And here for the umbrella version:

Also Liked

josefrichter

josefrichter

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.

NobbZ

NobbZ

PubSub, even though used by the channels, is not a web concern. It is to send (publish) messages to a couple of subscribers, in a way that the publisher does not need to know the subscribers, while also the subscribers do not need to know the publisher(s) in advance.

It can be used for a lot more things than just “web”.

Thomas-Sciaroni

Thomas-Sciaroni

In addition to what Jose mentioned, I also needed to update the children in
./rumbl_umbrella/apps/rumbl_web/lib/rumbl_web/application.ex
by adding

children = [
  ...
  RumbWeb.Presence
]

otherwise I was getting the error:

[error] GenServer #PID<{PID}> terminating
** (ArgumentError) argument error
(stdlib 3.13) :ets.lookup(RumblWeb.Presence, :pool_size)
    (phoenix_pubsub 2.0.0) lib/phoenix/tracker.ex:311: Phoenix.Tracker.pool_size/1
    (phoenix_pubsub 2.0.0) lib/phoenix/tracker.ex:240: Phoenix.Tracker.list/2
    (phoenix 1.5.6) lib/phoenix/presence.ex:401: Phoenix.Presence.list/2
    (rumbl_web 0.1.0) lib/rumbl_web/channels/video_channel.ex:40: RumblWeb.VideoChannel.handle_info/2
    (phoenix 1.5.6) lib/phoenix/channel/server.ex:344: Phoenix.Channel.Server.handle_info/2
    (stdlib 3.13) gen_server.erl:680: :gen_server.try_dispatch/4
    (stdlib 3.13) gen_server.erl:756: :gen_server.handle_msg/6
    (stdlib 3.13) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: :after_join
State: %Phoenix.Socket{assigns: %{user_id: ...
...}

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New

We're in Beta

About us Mission Statement