I'm developing a real-time Phoenix App using it's Channel and Socket modules. The App consists of a few processes and GenServers. I have a use case, where on an event (which is an API call from a microservice), I need to broadcast messages to all different topics on my channel on different timestamps. I have achieved this using Process.send_after(..) on my local machine for now. But my doubt is:
On a fleet of machines, because the API call will hit only a single machine in the cluster, other machines wouldn't be able to send the broadcast messages. And this would lead to inaccuracy. How can I let all the machines know of this particular event? Or am I doing it wrong?
Assuming you know the names of nodes in the cluster, you might loop nodes, calling
Node.spawn/2
on each:Uncomment the commented lines if the current node was already served, and [probably] somehow ensure the nodes are connected and alive upfront.
Also,
Node.spawn_link/*
might be worth to take a glance at.