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

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
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

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
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
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement