Enuzo

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?

Showing Posts 1 to 3

derek-zhou

derek-zhou

satom99

satom99

You must use Endpoint.broadcast/3 instead. Where Endpoint in this case is your application’s endpoint.


If you have a look on the source code for this broadcast/3 function I mentioned, you’ll notice it ends up calling PubSub.broadcast/4 too. 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

Enuzo OP

@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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
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
velrest
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
samoloth
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
asweet-confluent
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 Top

JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews