Phoenix:
I’m using Phoenix as a Broker, different clients (Android and iOS connected to PhoenixWeb.UserChannel
) and multiple instances of Microservices (MS), connected to PhoenixWeb.ServerChannel
, in Go. all will be connected to multiple instances of Phoenix (inter-connected via Node).
Presence:
I do use Presence to keep all information of Client and MS connected to Phoenix
Client Presence:
%{ node: Node.self(), channel: socket.topic, channel_pid: socket.channel_pid, user_id: socket.assigns.user_id, venue_id: socket.assigns.venue_id, device_id: socket.assigns.device_id, room_type: socket.assigns.room_type, }
MS Presence:
%{ node: Node.self(), channel: socket.topic, channel_pid: socket.channel_pid, user_id: socket.assigns.user_id, group: socket.assigns.group, name: socket.assigns.name, }
Send Message:
From ServerChannel, when an MS send a message to a client, first, it will get the list of Client Present and filter it to get the right item. Then, we will do this call below, which will call a method into PhoenixWeb.UserChannel
and do the push
. All good this work perfect :D…
send(item[:channel_pid], {:send_msg, %{"topic" => topic, "playload" => playload}})
Question:
Case: I do have N1 and N2 (instance of Phoenix). Client 1 is connected to N1 and MS is connected to N2. MS send message to Client 1
- I did try and it’s working but I’m wondering how Phoenix know the
channel_pid
is from N1 or N2? - What will happen, if I have the same PID name on N1 and N2 but each is linked to different process? Phoenix will still send the message to the right Node?