bboyadao
Need help to map kafka topic to liveview
I have a problem when integrate phoenix live view and kafka.
been a week i spend my free time to learn elixir.
Now i have a normal web app just display realtime data from kafka. i have done with producer from another server side. So now in elixir im using phoenix to serve web app.
the problem is i dont actually know how to map consumers topics data to web display.
im using kafka_ex library.
Please give me some advice.
Thank for reading.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 8 of 8 Posts
Matsa59
Simply subscribe to a topic from Phoenix live view (in mount).
Read data from Kafka and broadcast the data using Phoenix live view.
All your subscribers will receive the data inside a handle_info/3 function. In this function you will be able to assign data to Phoenix client socket.
If you need some code sample, ask in reply
—
If you want to keep you code with no coupling (business side vs web side), you can use Registry.
I wrote a lib that could interested you GitHub - wapitea/event_manager: A simple event manager based on elixir's Registry. · GitHub. It’s more sugar syntax than anything else.
It’s new and document may have some errors. You can read how to use registry for example or simply use it.
chulkilee
FYI Registry is local - so if you run distributed erlang then you cannot use it since kafka consumer process and liveview process is not in the same node.
Matsa59
I spoke about code architecture not multi node. But good reminder
But to resolve that kind of problem, there is an awesome lib call horde.
He doesn’t say the consumer and the Liveview are on different node. Otherwise he just need to create a simple api with Phoenix.
Matsa59
Also I totally forgot but something really nice is use
{:global, :name}.More information The scope of process name? - #5 by lucidstack
bboyadao
Thank you all.
I have using websocket but that performance are bad. That why im here.
I have done in console/terminal. so the main issue is in phoenix.
Iam new.
Please explain for me what can i do at handle_info/3.
Thanks
UPDATE!
I have do more code but i think im wrong some where. render function can not listen yield/stream. so must i using channel ?
Here is my live view file display.ex · GitHub
Matsa59
I think you should consider 2 parts on your apps.
The first one is the web, you will only deal with web things. You will create your LiveView, handle broadcasted messages …
The second one is your “real backend”, where you put all business stuff like consume kafka.
Then you will be able to focus on what to achieve step by step, instead of trying to do everything in one shot.
–
Here your goals (suggestion):
Consume kafka message (you can use GenStage here for example, or use any supervised process with a loop system to consume your kafka queue).
it will create the “consume” loop system. So everytime a new message income to your kafka, you’ll consume it asap.
Create your web page to display your data (at this point don’t use real data, create a “fake” data representation of what you will have / want to have)
Link both together. Basically, you want your “backend” to push information to your web page. A possible solution is use phoenix broadcast system (Phoenix.Endpoint — Phoenix v1.8.8).
At every step check if everything works as expected. For the first step, every time you push a message try to display it with a
IO.inspectfor example.Here an example of what you can do
In your backend you just have push the kafka message with:
Every time you pushed a message with
broadcast/3all liveviews that have been subscribe the the specified topic will receive the message. It mean, if you have 3 tabs on the same page (3 sockets so), the 3 sockets will execute thehandle_info/2so the 3 tabs will be updated in real time.bboyadao
Many thanks for your very detail. i’ll check it out and response.
bboyadao
It’s seem complex more then i thought at elixir.
i have create a repo here GitHub - bboyadao/minigame · GitHub
So could you give me a hand…
thanks