Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enobufs/sinc
Simple Inter-Node (cluster) Communication
https://github.com/enobufs/sinc
Last synced: 10 days ago
JSON representation
Simple Inter-Node (cluster) Communication
- Host: GitHub
- URL: https://github.com/enobufs/sinc
- Owner: enobufs
- Created: 2013-03-27T09:21:27.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-08-26T20:31:19.000Z (about 11 years ago)
- Last Synced: 2024-04-14T06:01:41.503Z (7 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
* Unicast
* 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 messagesvar n01 = myCh.createNode('node 01');
n01.on('message', function(node, msg, from) {
// Handle received message
})
n01.send('Hello, World!', 'node 02');## API
### Module
* [create(sincId, [redisPort], [redisHost])](#create)
* [setLogger(logger)](#setLogger)
* [Mode](#mode)### Class: Sinc (extends events.EventEmitter)
* [createChannel(chId)](#createChannel)
* [getNumChannels()](#getNumChannels)
* [Event: 'ready'](#Sinc_Event_ready)
* [Event: 'error'](#Sinc_Event_error)### Class: Channel (extends events.EventEmitter)
* [createNode(nodeId)](#createNode)
* [close()](#Channel_close)
* [getNumNodes()](#getNumNodes)
* [Event: 'ready'](#Channel_Event_ready)
* [Event: 'close'](#Channel_Event_close)### Class: Node (extends events.EventEmitter)
* [send(msg, to, [options])](#send)
* [broadcast(msg, [options])](#broadcast)
* [close()](#Node_close)
* [Event: 'message'](#Node_Event_message)## Module
### create(sincId, [redisPort], [redisHost])
Creates a Sinc object.* 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'
### setLogger(logger)
Set custom logger. The logger object must have the following method:* 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
### createChannel(chId)
Creates a channel object.* chId {string} - A unique channel ID within the sinc ID.
### getNumChannels()
Gets the number of channels currently active.
### Event: 'ready'
Notified when the sinc object become ready.CALLBACK: function( ) { }
### Event: 'error'
CALLBACK: function(err) { }* err {string} - A text that describes the error.
## Class: Channel
### createNode(nodeId)
Creates a node (a communication endpoint) object.* nodeId {string} - A unique node ID within the channel ID.
### close()
Close this channel.
### getNumNodes()
Returns the number of nodes on this channel.
### Event: 'ready'
Notified when the channel has become ready to use.CALLBACK: function( ) { }
### Event: 'close'
Notified when this channel has been closed.CALLBACK: function( ) { }
## Class: Node
### send(msg, to, [options])
Sends a message to a specified destiation, or a set of destinations.* 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.
### broadcast(msg, [options])
Broadcasts a message.* 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.
### Event: 'message'
Notified when a message has been received on this node.CALLBACK: function(node, msg, from) { }
hljs.initHighlightingOnLoad();