anandgeorge
Hi,
I have an implementation in which the backend is in two parts. One handles business logic and the other is a LiveView server.
The Business Logic publishes data at regular intervals over PubSub to multiple consumers including LiveView.
How do I set up my LiveView server to subscribe to this data.
I have evaluated handle_info in LiveView but it seems to be designed for sending updates to connected clients, not to handle subscription from another service.
Thanks.
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
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
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dnsbty
I have a tutorial that shows you how to get PubSub and LiveView working together here: https://dennisbeatty.com/how-to-create-a-todo-list-with-phoenix-liveview/
But if you’ve already got the
handle_infocallback in place, you’ll probably just need to callPhoenix.PubSub.subscribe/2in your live view’sinitcallback.anandgeorge
Hi,
Thanks for taking the trouble to answer and sharing the link. However it does not seem to help.
Just to give further context. It’s an umbrella app with a publisher, subscriber (for business logic), liveview.
This is the process I’ve followed.
Got the publisher and subscriber working over PubSub.
Copied the Pubsub.subscribe function to the mount implementation in LiveView.
Copied the handle_info implementation in PubSub just after the handle_events in the liveview app.
One thing I noticed that handle_info in pubsub takes state as the second argument while handle_info in liveview takes socket as the second argument. Tried both combinations but they don’t seem to talk.
Also checked observer and there is no link between the PubSub subscription process and the LiveView subscriber process.
Thanks.
Sebb
When the live-view process subscribes to a topic (eg in
mount) it should receive messages broadcasted to that topic inhandle_info.handle_infoin the live view process gets the live-socket as second argument.Try a minimal example, if that still not works post it here.
derek-zhou
You need to make sure the subscribe is protected by
connected?/1as described here:[Phoenix.LiveView — Phoenix LiveView v1.2.5]
anandgeorge
Thanks. It works now.
Sebb
Could you please tell what you changed, could be useful for other people finding this topic with similar problems.
The "not-connected-subscribe’ would just be useless then, but it would still subscribe connected (ie in the live-view process) and work, right?
anandgeorge
Sure. The issue was more conceptual.
Coming from a Javascript / Nodejs background I presumed that LiveView works like a server. So when I run iex -S mix phx.server it starts up the server, runs mount and configures it’s responses based on implementations of handle_event, handle_info etc. I was hoping to broadcast messages to clients that then connected. In short the server runs before a connection is made. I was therefore watching out for the subscription to run and get a log of the messages, which obviously didn’t happen.
As I can see LiveView spins up a process for each connection. Mount doesn’t run and therefore subscription doesn’t initiate till the client connects.
Once connected the subscription was initiated. There was a small issue with implementation of handle_info which logged an error. Corrected that and now it works.
Thanks once again.