N
N
Nikolay2016-03-07 00:32:24
Node.js
Nikolay, 2016-03-07 00:32:24

How to pass data from one process to another process on nodejs?

Knowing the pid of the process launched using child_process.exec, is it possible to somehow transfer an object with data to this process at any time and vice versa?
I can’t use sockets, because I have to load the master process, and it needs to be protected from any influences as much as possible.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
Timur Shemsedinov, 2016-03-07
@Dinfyru

Just through sockets, you can transfer from one child process to another, but through child_process (and through cluster), i.e. through IPC (inter-process communication) everything will go only through the master process. Listen to UDP in each process, this is convenient if you need to send to everyone at once, and if only to a specific process, then when forking, give it a port number in the parameters and open a separate server TCP socket in each worker. The master process can send each worker a correspondence between ports and pid (if necessary), otherwise you can simply know that the ports go, for example, from 2000 to 2019 (that is, there are 20 of them open) and send to one of them.

N
Nicholas, 2016-03-07
@ACCNCC

pm2.keymetrics.io/docs/usage/cluster-mode
Redis

I
Ivan, 2016-03-07
@LiguidCool

IMHO through the database.

S
Stalker_RED, 2016-03-07
@Stalker_RED

https://ru.wikipedia.org/wiki/AMQP is not your option? With queues, sharding and other goodies and sparks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question