Phoenix Pubsub and :pg2.which_groups

As I a beginner with Phoenix Pubsub, and I got the strange situation need to help to explain.
I have small application use Phoenix Pubsub, then there are two case:

  1. Run application with “mix run --no-halt”, and check logs from code IO.puts(“Check pg2 groups: #{inspect(:pg2.which_groups())}”), then got [phx: MyDemo.PubSub.Adapter]
  2. Run application with “iex --sname demo_node -S mix phx.server --no-halt”, and check logs from code IO.puts(“Check pg2 groups: #{inspect(:pg2.which_groups())}”) , then got [phx: Phoenix.PubSub.PG2, phx: MyDemo.PubSub.Adapter]

I wonder why there is the pg2 group “phx: Phoenix.PubSub.PG2” in case #2. Could anyone please explain?

It is not much problematic, as I can get the correct pg2 group and get the members to send directly messages to. But there is still a bit confuse and need to clarify. Then could you please help @chrismccord ?

Phoenix pubsub adds this process as the pubsub adapter. You can see the source code for it at https://github.com/phoenixframework/phoenix_pubsub/blob/v1.1.2/lib/phoenix/pubsub/supervisor.ex#L7

My guess is that this is only added when serve endpoints is true, although I haven’t read through the code deep enough to answer that with 100% certainty.

Thanks @sb8244, as I just begin then there is so many things to explorer.