verbose

Distributed Event Bus

npm install verbose
3 downloads in the last week
40 downloads in the last month

verbose Build Status

Distributed event bus

Features

  • Automatic reconnect with back-off
  • Reconnect resilience: messages get buffered for retransmission if necessary
  • Create any topology of nodes
  • Pluggale transport

Create a Node

var verbose = require('verbose');
var node = verbose();

You can also give it some options:

var options = {
  node_id: 'NODE-ID-000001'
};

var node = verbose(options);

Here are the options:

option description default
node_id node identifier for other peers random UUID
timeout inactivity timeout (ms) 60000
bufferTimeout maximum retransmit resilience 900000
bufferMax maximum number of buffered messages kept by peer 1000
acknowledgeInterval message acknowledge interva (ms) 1000
maxPeers message acknowledge interva (ms) 1000
transport transport name or object. If object, must provide a listen and a connect methods. See example "tcp"

Make it listen

node.listen(port);

Connect to another node in another process

node.connect(port[, host]);

Emit events on a node

node.emit('event', 'a', 1);

Receive events

node.on('event', function() {
  console.log('got event:', arguments);
});

End a Node

node.end();

Underlying stream

You can access the underlying stream:

node.stream.on('end', function() {
  console.log('node ended');
});

Besides being a duplex stream, it emits the following events:

  • connect - when the peer connects to the remote peer (transport layer)
  • peerid - when the remote peer gets identified during the hand-shake protocol
  • initialized - when the peer handshakes with the remote peer
  • acknowledge - when there is an acknowledge message from the remote peer
  • disconnect - when a peer gets disconnected from the remote peer
  • reconnect - when the peer reconnects to the remote peer
  • backoff - when the reconnect algorithm has to back off because of an unsuccessful retry

Peer control

When connecting you can get access to the peer object:

var peer = node.connect(port, host);

Which you can then use to end:

peer.end();

Licence

MIT

npm loves you