RudolfVonKrugstein

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 :slight_smile:

Marked As Solved

BradS2S

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")

I found this book by @sb8244 really helpful.

Also Liked

dimitarvp

dimitarvp

I will not comment on your bigger goal but :pg2 got replaced by :pg – so you could check that out.

RudolfVonKrugstein

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!

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement