Node.js fork communicator (messages between processes)
Small library for communication between forks. This library is created for small projects that do not need to store queues and no guarantee of receipt. For more complex tasks, use rabbitmq or another message-broker.
Install
npm install forks-communicator --save
Usage examples
Just clone, go to the example directory and run fork.js
or worker.js
.
fork.js - Fork example
Create master and forks then wrap forks to the communicator. For master use forks-communicator
and for forks forks-communicator/fork
.
const setup subscribe emit = ;const fork = ;const join = ; // Wrap forks in the communicator;; // Subscribe to channels from master process;;
worker.js - Worker example
Create master and forks then wrap forks to the communicator. For master use forks-communicator
and for forks forks-communicator/fork
.
const setup subscribe emit = ;const Worker = ;const join = ; // Wrap forks in the communicator;; // Subscribe to channels from master process;;
child/process.js
const emit subscribe = ; // Subscribe to channel from fork process; // Emit message to "say" channel from fork process; // Emit message to "meow" channel after second from fork process;
child/another_process.js
const emit subscribe = ; const all = ; ; ;
Work result
[master] recived: [fork] Meow from fork[master] recived: [another fork] Meow from another fork[another fork] Meow recived: [fork] Meow to another fork[fork] Message