julismz
Hi all!
I’m trying to subscribe to a PubSub on a different module when I run the task which is gonna broadcast.
In the first place, I call an async task, which calls a function on a specific GenServer. That job could take 10 seconds.
I want to allow user to keep navigating the site and subscribe everywhere to that topic, waiting for the PubSub reply message.
If I stay and wait, I receive the message with the handle_info, but if I change the page, even subscribed again, the broadcast is lost on the space…
To my surprise, seems like “broadcast” only send the message to a specific process instead “broadcast” to all the process…
I’m thinking on face this with WebSockets, but I thought that PubSub maybe has something for these “persist” cases… SQS or MQ could be another option but I think that is too much…
Any suggestion?
Trending in Questions
Other Trending Topics
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
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
You can broadcast on a channel, and receive on another one…
You can do it per user, or per session.
As long as users have their own custom channels, it’s possible to use it for reply. If You subscribe to this channel in each liveview, that should be fine.
julismz
Is what I’m trying to do… My channel / topic is called “blockchain”.
On my liveview mount()
On my GenServer:
On my liveview:
If I keep waiting, I receive the message. If I change the view, I get nothing…
kokolegorille
You also need another one…
Phoenix.PubSub.subscribe(App.PubSub, "session:#{session_id}")You can generate a random session_id and use it as a personal channel, where You receive anything personal.
You might use user instead, if your users needs to be authentified.
julismz
Ok… so now I have this:
And on the GenServer side I should broadcast to…?
I’m not sure about following you… Thanks for your patience…
julismz
This is the flow:
1)I subscribe on liveview.
2)I send a job to GenServer using Task Supervisor async.
3)I move to another view when I’m also subscribed.
4)I receive the PubSub message there.
broadcast is only on GenServer… The first job is triggered by a Task:
kokolegorille
Something like this… the main part is You will connect to this custom channels in all your liveviews.
julismz
Is what I do… but message does not arrives… I got
Client #PID<0.1240.0> is deadkokolegorille
Using Task Supervisor async will link the caller, and that is not good if the caller is the liveview process… because it will die when the liveview process dies.
julismz
Seems like RabbitMQ or SQS is my only alternative here… so bad…
kokolegorille
There are more tools than just Task async… for example, having a manager gen_server being the middle-man.
When You call your job, You do it through a GenServer, that does the call to the worker. Then, the liveview can die, but the worker won’t.
You might look at OTP tools first, before RabbitMQ and SQS. There are many, and the Task module is one I use when I don’t need to control the process.