jakub-zawislak
I’m new to distributed elixir.
I have two clean installations of Phoenix 1.4.2 - apps named A and B. I’m running these with --sname option. I can run command from another application using :rpc.call. Can I subscribe to Phoenix.PubSub from another app?
I have tried:
iex(a@MacBook-Pro)1> Node.connect :"b@MacBook-Pro"
iex(a@MacBook-Pro)2> Phoenix.PubSub.subscribe(B.PubSub, "topic")
# throws argument error - :ets.lookup(B.PubSub, :subscribe)
Should it be somehow wrapped by a GenServer on the B side and used with Node.spawn_link? Is there some easier solution? First I wanted to broadcast messages between two apps installed on same server using websockets but then I thought there should be an easier method.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
blatyo
I’m not super familiar with the implementation details, but I’ll try to describe it conceptually and hopefully that’ll help.
Phoenix.PubSubworks, by creating a cluster of different nodes. You need to start aPhoenix.PubSubprocess on every node in the cluster. You can specify an adapter, which allowsPhoenix.PubSubto discover what other nodes are available to connect to. In the case of the redis adapter, each node will connect to redis and messages will be sent through that. In the case of PG2 (the default),Phoenix.PubSubwill connect with otherPhoenix.PubSubprocesses on any of the nodes already clustered by the nodes being connected.So, you’ve correctly connected the nodes. But it looks like you’ve not started a
Phoenix.PubSubprocess. So, when you callPhoenix.PubSub.subscribe/2, the process that would’ve setup stuff locally on the current node hasn’t done so and you’re getting an error about a lookup on an ets table not existing.I think in the simple iex session you’re just missing something like:
Phoenix.PubSub.PG2.start_link(name: B.PubSub)jakub-zawislak
My apps are clean installations of Phoenix, so they have PubSub enabled by default in
config.exs:I also tried to manually set up another PubSub in
application.ex:I can access this PubSub from the B app:
but I still cannot connect from the A app.
blatyo
I did some brief digging. The
server_nameneeds to be the same for two PubSub’s to connect via PG2.https://github.com/phoenixframework/phoenix_pubsub/blob/v1.1.2/lib/phoenix/pubsub/pg2_server.ex#L42-L44
So, the
nameargument needs to be the same as what it is on node A. You also still need to connect the nodes if you’re not doing that.jakub-zawislak
I figured it out without the
Phoenix.PubSub. I think it’s all I need.Create pg2 group in A
Connect to group in B
Send message in A
Handle messages from A in B
jakub-zawislak
Maybe someone will be interested in my final implementation of the subscriber module
blatyo
You can just do
send(self(), :join_pg2)lkuty
I invite you to have a look at Distributed Phoenix Chat with PubSub PG2 adapter.