RudolfVonKrugstein
Pubsub system, where I know more about the subscribers
Hi,
I am looking for a way to create a pubsub system where the publisher has a little bit more control over the subscribers:
- depending on the state of the publisher, I want to send a “welcome” message to every new subscriber, informing them about some aspects of the publisher state.
- The publisher does some heavy computing, but if there are no subscribers it shall stop. So it would be nice if it could know if any subscribers are there.
Being very new to Elixir, I am trying to figure out a good way to do this.
First I tried :pg2, but that seems to not exist anymore in OTP24.
Can Phoenix.PubSub be convinced to five me this information?
Or what can I use to replace :pg2.
Thanks for any hints ![]()
Marked As Solved
BradS2S
I’m pretty sure you could just use Phoenix.PubSub out of the box. Perusing the pg2 adapter module, it does check for :pg first.
Just generally speaking you could do something like:
Phoenix.PubSub.subscribe(MyApp.PubSub, "user")
Phoenix.PubSub.broadcast(MyApp.PubSub, "user", :welcome_message)
Phoenix.Tracker.list(MyApp.PubSub, "user")
Also Liked
dimitarvp
I will not comment on your bigger goal but :pg2 got replaced by :pg – so you could check that out.
RudolfVonKrugstein
Oh, interessting. I have seen :pg. But bebause it is kind of unintuitive, that :pg replaced :pg2 and not the other way around, I did not think of it.
Thanks for the hint!
Popular in Questions
Other popular topics
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
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









