Node.js的进程间事件发射器? [英] Inter-process event emitter for Node.js?

查看:98
本文介绍了Node.js的进程间事件发射器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此刻,我正在使用 EventEmitter2 作为应用程序内的消息总线,我真的很喜欢它.

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-process, but also inter-process. My ideal candidate would …

  • …与EventEmitter2(替代产品")API兼容,
  • …仅使用操作系统资源即可在没有专用服务器或外部服务(例如数据库,消息队列等)的情况下工作,
  • …用纯JavaScript编写,
  • …在内存中运行,因此不需要持久性.

不需要需要做什么:

  • 它不需要在Windows上运行,OS X和Linux都可以.
  • 如果它只能在单台计算机上运行,​​并且不需要了解网络,就可以了.

有什么想法或提示吗?

PS:可以推荐一个可用的产品很好,但是如果您可以指导我自己如何做无服务器的事情,那也可以.

PS: It is fine if you can recommend an available product, but it is also fine if you can point me into a direction of how to do the server-less thing by myself.

推荐答案

在我看来,这是您的选择.

Here are your options as I see them.

  1. process.fork/send .如果两个进程都是节点,则节点核心通过此API提供一种简单的,事件驱动的IPC机制.它与process.fork配对,因此,如果您的进程是基于节点的主进程,并且是多个基于节点的工作程序/支持子进程,则process.send可能是一个可行的选择. http://nodejs.org/docs/latest/api/all.html#all_child_process_fork_modulepath_args_options

  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

  • 基于事件,但不包含EventEmitter2
  • 双向
  • 效率
  • 仅使用操作系统资源
  • 内存中
  • javascript

使用节点核心的TCP网络通过Unix域套接字进行连接. http://nodejs.org/docs/latest/api/all.html#all_net_connect_options_connectionlistener

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

  • 基于静止事件但原始数据流,而不是高级消息
  • 双向
  • 内存中
  • javascript

好的旧TCP.

  • 基于静止事件但原始数据流,而不是高级消息
  • 双向
  • 内存中
  • javascript

节点到节点 socket.io

  • 基于事件,但不包含EventEmitter2
  • 双向
  • 内存中
  • javascript

在所有情况下,一旦建立连接即可进行双向通信,但始终存在第一个对等方(TCP或socket.io中的服务器,process.fork中的父进程)和第二个对等方(TCP或socket中的客户端)的概念.io,process.fork中的子进程).

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).

这篇关于Node.js的进程间事件发射器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆