ericlathrop
I’ve got an umbrella app with a Phoenix app, and some vanilla elixir apps. Is there a way to broadcast to a Phoenix channel from a vanilla elixir app? I’d like to avoid adding a dependency on the Phoenix app to reference its Endpoint.
I’m working on using Phoenix.PubSub to do this, but I’m not having any luck. This code:
Phoenix.PubSub.broadcast(Www.PubSub, topic, %{
__struct__: Phoenix.Socket.Broadcast,
topic: topic,
event: event,
payload: payload
})
Is giving me this error:
[error] GenServer #PID<0.952.0> terminating
** (UndefinedFunctionError) function Www.TimeChannel.handle_out/3 is undefined or private. Did you mean one of:
* handle_in/3
* handle_info/2
(www) Www.TimeChannel.handle_out("now", %{now: "yolo"}, %Phoenix.Socket{assigns: %{user_id: 14904}, channel: Www.TimeChannel, channel_pid: #PID<0.952.0>, endpoint: Www.Endpoint, handler: Www.UserSocket, id: "users_socket:14904", joined: true, pubsub_server: Www.PubSub, ref: nil, serializer: Phoenix.Transports.WebSocketSerializer, topic: "time:now", transport: Phoenix.Transports.WebSocket, transport_name: :websocket, transport_pid: #PID<0.909.0>})
(phoenix) lib/phoenix/channel/server.ex:234: Phoenix.Channel.Server.handle_info/2
(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:667: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: %Phoenix.Socket.Broadcast{event: "now", payload: %{now: "yolo"}, topic: "time:now"}
State: %Phoenix.Socket{assigns: %{user_id: 14904}, channel: Www.TimeChannel, channel_pid: #PID<0.952.0>, endpoint: Www.Endpoint, handler: Www.UserSocket, id: "users_socket:14904", joined: true, pubsub_server: Www.PubSub, ref: nil, serializer: Phoenix.Transports.WebSocketSerializer, topic: "time:now", transport: Phoenix.Transports.WebSocket, transport_name: :websocket, transport_pid: #PID<0.909.0>}
I’m confused about it wanting to use handle_out because I’m not using intercept anywhere, but maybe I just have my message format wrong. I was hoping to get the vanilla elixir app to broadcast directly to the web browser clients.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
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
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
mgwidmann
I’m curious to her the answer to this as well…
OvermindDL1
Honestly I’d probably be lazy and make a configuration for the module to call on, then in the app I’d get that config entry and just call
whateverConfig.broadcast(...)on it, and just configure my endpoint in the config. ^.^chrismccord
handle_out is being called because It’s not respecting the channel subscriber fastlanining, but without seeing your code it’s hard to say why that is. In any case, instead of trying to build cheat by building the
Phoenix.Socket.Broadcast, I would have the external app broadcast “raw” messages over pubsub that your phoenix app subscribes to. You could have the channel subscribe to the topic and forward the message inhandle_info, or you can have server(s) in your app subscribing to external topics/events, and then relaying them to channels viaMyApp.Endpoint.broadcast. This way you aren’t coupling the external app to your channel layer directly. This also gives you a place to do any necessary data munging from the external data to the client representation.ericlathrop
I did get it to work by making these changes:
and I call it like:
handle_infointo mySessionChannel:I found that code at the bottom of the Channel docs under “Subscribing to external topics”.
It works, but seems a little fragile. I like @chrismccord’s idea of making a server (GenServer?) that uses
Phoenix.PubSubto listen to my own format message, and thenMyApp.Endpoint.broadcastthem. How do I prevent double-broadcasts when I have 2 webservers running each with their own GenServer doing the message forwarding?keb
I’m facing a similar problem, that is, in an umbrella app there is one app that supervises a PubSub server, another one that broadcasts a message, and a third one, which is the Phoenix app that contains the relevant channel. There is also Presence in use, and apparently “fastlaning” has been disabled for that as well:
My solution was to simply implement the missing
handle_outcallback:As long as the Phoenix app creates the PubSub server this isn’t needed, but it’s suddenly required when you configure your endpoint to use an external PubSub server instead. Why?
@chrismccord is there documentation on what fastlaning actually means, what it does and why it’s disabled in some cases? I couldn’t find anything about it on hexdocs, and I’m not sure where to look in the code.
dorian-marchal
Same question, I have a channel that broadcast events (from
handle_in), with:This works well until I subscribe to a
PubSubin thejoincallback:Since I have added this subscription, the events broadcast trigger errors:
I can add the missing
handle_out/3callback but this doesn’t feel right and I don’t understand why I should add it.What am I missing?
EDIT: I found out why: I was using the same topic name for my channel and my
PubSubsubscription. I didn’t realize channels and “global”PubSubshared the same namespace for topics.