I can use process.send
to send a message from a worker to a master. I can use the following code to send a message from the master to each worker.
for (var id in cluster.workers) {
cluster.workers[id].send({command: 'doSomething'});
}
To send a message from a worker to other workers I have to send a message to the master and then have it forward the message. This results in the original sender also receiving the message and is something that I'd like to avoid but I can live with it!
I also tried sending the message directly from the worker like it's done in the master but cluster.workers
is undefined
in workers.
Is there any other way to do this?