I figured it out without the Phoenix.PubSub. I think it’s all I need.
Create pg2 group in A
defmodule A.Application do
def start(_type, _args) do
:pg2.create :some_group
# ...
end
Connect to group in B
defmodule B.Application do
def start(_type, _args) do
children = [
# ...
{B.Worker, []},
]
# ...
end
defmodule B.Worker do
use GenServer
def start_link(opts) do
{:ok, pid} = GenServer.start_link(__MODULE__, :ok, opts)
true = Node.connect(:"a@MacBook-Pro")
:ok = :pg2.join(:some_group, pid)
{:ok, pid}
end
end
Send message in A
iex(a@MacBook-Pro)1> [pid] = :pg2.get_members :some_group
iex(a@MacBook-Pro)2> send(pid, :hello)
Handle messages from A in B
defmodule B.Worker do
def handle_info(msg, state) do
IO.inspect msg
{:noreply, state}
end
end






















