MultiNodes
Running many logical nodes in different machines, to build a distributed node cluster. Each logical node can host application objects, and interchange messages.
Description
In some of my projects, I need to run object applications that interchange message with other running processes. Instead of having each process open its own TCP/IP port and connecting to the other processes that host the same object application, I want to have an utility to manage such cases. MultiNodes does:
- Start a logical node in a worker process.
- Expose the logical node to other nodes in the node set.
- Connect to other logical nodes.
- Declare and exposes the local services/applications.
- Exchange messages (simple JavaScript objects serializable to JSON) between distributed services/applications.
See a logical node as an object running in a machine, using Node.js.
See a service/application as an object that sends and receives messages.
Related projects that need this functionality:
- SimpleStorm Simple Storm-like distributed application implementation.
- AjFabriqNode A Distributed Application Framework for NodeJs.
Example: SimpleStorm can run local topologies, like the original Storm Java project. But it can run distributed topologies, too. Each task in those topologies can emit message to the other tasks, that can be local or remote. Instead of managing the connection and discovery of the other remote machines running topologies by itself, SimpleStorm could rely on MultiNode to manage the distributed logical nodes.
Installation
Via npm on Node:
npm install multinodes
Usage
Reference in your program:
var multinodes = ;
Create a node:
var node = multinodes;
It creates a node with a random name.
var node = multinodes;
It creates a node with the given name.
var node = multinodes;// a server starts listen on portnodestart { // For each connected client // it will receive the description of remote node};
Register an application with a description:
node;
application
should be an object with a process(msg)
function to receive messages. description
is an optional
object that has application-dependent information.
Get node description:
var description = node;
It includes the node name, the registered applications, and the names of the known remote nodes.
Connect a node to a published server node:
node;
See network test.
Send a message to a node:
node;
Send a message to a remote/connected node:
node;
Examples:
// Send a message to an application, to be processed as app.process(msg)node;// Send a call to an application, to be processed as app.[action](args...)node;
Usually, instead of node.process
you can use the following methods:
Send a message to app.process(msg)
node;
Call a method (action) in application as app.action.
node;
args
is an array.
Stops a node:
node;
Run a function in a node (local or remote)
node; // args is an array node;
Run a function in an application (local or remote)
node;node;
Using this functions you can run code at remote nodes. See Collatz Sample: the server node code sends code to every new client node, to load and start application.
Development
git clone git://github.com/ajlopez/MultiNodes.git
cd MultiNodes
npm install
npm test
Samples
TBD
To do
- Samples
- Improve README.md
Versions
- 0.0.1: Published.
- 0.0.2: Published. New sample, runInNode, runInApplication, serializing function.
Contribution
Feel free to file issues and submit pull requests � contributions are welcome.
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test
continues to pass.