'message' 事件


如果使用 IPC 通道衍生 Node.js 进程(参见子进程集群文档),则只要子进程收到父进程使用 childprocess.send() 发送的消息,就会触发 'message' 事件。

消息会进行序列化和解析。 生成的消息可能与最初发送的消息不同。

如果在衍生进程时使用了 serialization 选项设置为 'advanced',则 message 参数可以包含 JSON 无法表示的数据。 有关更多详细信息,请参见 child_process 的高级序列化

If the Node.js process is spawned with an IPC channel (see the Child Process and Cluster documentation), the 'message' event is emitted whenever a message sent by a parent process using childprocess.send() is received by the child process.

The message goes through serialization and parsing. The resulting message might not be the same as what is originally sent.

If the serialization option was set to advanced used when spawning the process, the message argument can contain data that JSON is not able to represent. See Advanced serialization for child_process for more details.