Enuzo
I have an Elixir 1.54 and Phoenix umbrella app containing:
[AdminWeb]
[Admin]
[DisplayWeb]
The [AdminWeb] calls a function defined in [Admin] that pulls information from a
Database, then converts it to a list of maps and should broadcast it to DisplayWeb channel:
[AdminWeb] → [Admin] → [DisplayWeb]
The code in [Admin] looks like this:
# news.ex
def news_sort(id_list) do
news_payload = news_items_from_db() |> struct_to_map()
PubSub.broadcast(Admin.PubSub, "cast:news", news_payload)
end
The code in [DisplayWeb] looks like this:
#news_channel.ex
def join("cast:news", _payload, socket) do
self() |> send({:after_join, "cast:news"})
{:ok,socket}
end
def handle_info({:after_join, "cast:news"}, socket) do
broadcast!(socket, "newscast", %{data: news_payload})
{:noreply, socket}
end
The PubSub.broadcast in [Admin] returns :ok message but the [DisplayWeb] does not receive any message. It neither works not returns any error message.
Please, what’s wrong with the code? What’s the right way to implement this solution?
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
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
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
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
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
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
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
derek-zhou
you forgot to subscribe the message.
satom99
You must use
Endpoint.broadcast/3instead. WhereEndpointin this case is your application’s endpoint.If you have a look on the source code for this
broadcast/3function I mentioned, you’ll notice it ends up callingPubSub.broadcast/4too. But the catch here is that it is broadcasting a%Phoenix.Socket.Broadcast{}struct instead of plain data like you are doing. And this struct is most likely the language phoenix channels speak internally. Which, in other words, means that you are broadcasting a message that channels cannot understand. And so this explains why your clients receive no message.Enuzo
@derek-zhou, @satom99, thanks for your response. I’ve been advised to use PG2 since AdminWeb/Admin and DisplayWeb runs on two separate servers(4001, 4002). I’m currently researching how to use it properly.