Inter-process event emitter for Node.js?

后端 未结 1 1716
长情又很酷
长情又很酷 2021-01-02 18:32

At the moment, I am using EventEmitter2 as a message bus inside my application, and I really like it.

Anyway, now I need a message bus which does not only work in-pr

相关标签:
1条回答
  • 2021-01-02 18:52

    Here are your options as I see them.

    1. process.fork/send. If both processes are node, node core provides a simple, event-driven IPC mechanism via this API. It pairs with process.fork so if your processes are a node-based master and several node-based worker/support subprocesses, process.send might be a viable choice. http://nodejs.org/docs/latest/api/all.html#all_child_process_fork_modulepath_args_options

      • event-based, but not EventEmitter2 drop-in
      • bi-directional
      • efficient
      • uses only OS resources
      • in-memory
      • javascript
    2. Use node core's TCP networking to connect via a unix domain socket. http://nodejs.org/docs/latest/api/all.html#all_net_connect_options_connectionlistener

      • still event based but raw data stream as opposed to high-level messages
      • bi-directional
      • in-memory
      • javascript
    3. Good old TCP.

      • still event based but raw data stream as opposed to high-level messages
      • bi-directional
      • in-memory
      • javascript
    4. node-to-node socket.io

      • event based, but not EventEmitter2 drop-in
      • bi-directional
      • in-memory
      • javascript

    In all cases you get bi-directional communication once connected, but there is always the concept of the first peer (server in TCP or socket.io, parent process in process.fork) and second peer (client in TCP or socket.io, child process in process.fork).

    0 讨论(0)
提交回复
热议问题