0.0.0 • Published 3 years ago

sinc v0.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

sinc

Simple Inter-Node (cluster) Communication, powerd by Redis.

Installation

(TODO)

Features

  • Real-time messaging between (server/cluster) nodes via Redis.
  • Simple API - easy to use!
  • Supports string, JSON object and binary.
  • Messaging types:
    • Unicat
    • Multicast
    • Broadcast
  • Transfer Modes:
    • Inband: Deliver message inband (sending user data over redis pub-sub)
    • Outband: Deliver message outband (good for unicasting large data)
    • Auto: (not implemented yet)
  • Support of multiple 'channels' - a logical communication domain between nodes.

Usage

Create my sinc object

var sinc = require('sinc');
var mySinc = sinc.create('sinc for my app');

Create a channel

var myCh = mySinc.createChannel('my channel');

Create a node, then send & receive messages

var n01 = myCh.createNode('node 01');
n01.on('message', function(node, msg, from) {
	// Handle received message
})
n01.send('Hello, World!', 'node 02');

API

Module

Class: Sinc (extends events.EventEmitter)

Class: Channel (extends events.EventEmitter)

Class: Node (extends events.EventEmitter)

Module

  • sincId {string} - Sinc object ID. Typically an unique string that represents your application.
  • redisPort {number} - Redis port number. Defaults to 6379.
  • redisHost {string} - Redis host name. Defaults to 'localhost'
  • error()
  • warn()
  • info()
  • debug()

By default, sinc module uses 'fuzelog'.

Mode {object}

Transfer mode.

  • Inband: 0 - Default. Data is sent using redis publish.
  • Outband: 1 - Data is stored in redis first then notify receiver of the data using pubsub.
  • Auto: 2 - Let sinc decide which mode should use. (not implemented yet)

Class: Sinc

  • chId {string} - A unique channel ID within the sinc ID.

CALLBACK: function( ) { }

  • err {string} - A text that describes the error.

Class: Channel

  • nodeId {string} - A unique node ID within the channel ID.

CALLBACK: function( ) { }

CALLBACK: function( ) { }

Class: Node

  • msg {string|object|Buffer} - A message to send. When the type is 'object', it assumes the object is a JSON object.
  • to {string|array} - Destination node(s).
  • options {object}:
    • mode {number} - Transfer mode. Mode.Inband by default.
  • msg {string|object|Buffer} - A message to send. When the type is 'object', it assumes the object is a JSON object.
  • options {object}:
    • mode {number} - Transfer mode. Mode.Inband by default.
    • loopback {boolean} - Whether to loopback the broadcasted message.

CALLBACK: function(node, msg, from) { }