gang

0.0.3 • Public • Published

Gang.js

Build Status

The Gang

An inter-process communication, PubSub messaging and Web Proxy process collaboration mesh library for Node.js

Features

  • IPC (inter-process communication) using Pub/Sub emitters using axon.js
  • Send broadcast messages to all nodes
  • HTTP reverse proxy

Install

npm install gang

Example

Setup the alley (Server)

/**
 * Alley:
 * - listen for publications from gangsters on subAddress
 * - proxy http connections requests to httpAddress : httpPort
 */
var alley = require('gang').alley({
    subAddress: 'tcp://127.0.0.1:8990',
    httpAddress: '0.0.0.0',
    httpPort: 88888
}).onRegister(function (gangster) {
    console.log('A gangster named %s has joined', gangster.name);
});

Add gangsters (Clients)

/* A gangster */
var capone = require('gang').gangster('Capone', {
    subAddress: 'tcp://127.0.0.1:8991',
    http: {
        rules: {
            '^/capone(/.*)': '$1'  /* replaces web requests path with regexp */
        },
        address: '127.0.0.1',
        port: 8992
    }
}).onMessage(function (name, message) {
    console.log('Message from: %s >>> %j', name, message);    
}).connect('tcp://127.0.0.1:8990'); /* connect to alley's subscription socket */
 
/* Another gangster */
var scarface = require('gang').gangster('Scarface', {
    subAddress: 'tcp://127.0.0.1:8993',
}).onReady(function () {
    setInterval(function () {
        scarface.emit('Capone', { timestamp: new Date, random: Math.random() });
    } , 1000);
}).connect('tcp://127.0.0.1:8990'); /* connect to alley's subscription socket */

Test

npm test

Methods

...

Events

...

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    1
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i gang

Weekly Downloads

1

Version

0.0.3

License

MIT

Last publish

Collaborators

  • xenomuta