Messenger.js - Fast Node.js Communication Library
Installation
npm install messenger
What is Messenger.js?
Messenger.js is a library that makes network communication via JSON dead simple and insanely fast!
Example:
var messenger = ; client = messenger;server = messenger; server; ;
Output:
> 'you':'got it'> 'you':'got it'> ...etc...
Features
Messenger.js is very flexible and can handle everything you need.
- Supports Request / Reply Communication using round robin
- Supports Publish / Subscribe (fanout) Communication
- Supports Fire and Forget Communication
- Supports middleware plugin for messenger Listeners (servers)
- Extremely fast (disables TCP Nagle's algorithm)
- Fault tolerant: clients will reconnect to servers even if server goes down and comes back later
- Elegant API
- Easily involves multiple servers
- Zero dependencies on other libraries
Pub Sub Example - .shout
Example
var messenger = ; // here we have 4 servers listening on 4 different portsvar server1 = messenger;var server2 = messenger;var server3 = messenger;var server4 = messenger; server1; server2; server3; server4; // a client that can be used to emit to all the serversvar client = messenger; ;
Output
> server 1 got some data> server 2 got some data> server 3 got some data> server 4 got some data> ... repeat ...
Multi-Server Request Reply - .request
Messenger uses round robin to pick a server to send data to.
Example
var messenger = ; // here we have 4 servers listening on 4 different portsvar server1 = messenger;var server2 = messenger;var server3 = messenger;var server4 = messenger; server1; server2; server3; server4; // a client that can be used to emit to all the serversvar client = messenger; ;
Output
> server 1 got some data
Fire and Forget with Multiple Servers - .send
Again, using round robin to pick a server to send data to.
Example
var messenger = ; // here we have 4 servers listening on 4 different portsvar server1 = messenger;var server2 = messenger;var server3 = messenger;var server4 = messenger; server1; server2; server3; server4; // a client that can be used to emit to all the serversvar client = messenger; ;
Output
// via one of the 4 servers> 'some': 'data'
Plugin (Middleware) Example
Take a look at the function authRequired.
You may augment the value of data by changing m.data (see Example).
Example
var messenger = ; var server = messenger;var client = messenger; { if dataauthorized mdatacoolness = 10; // modify m.data if you want it passed, not data mnext; // continuation passing return; m;} server; var auth = false;;
Output
> error: 'not authorized'> you:'got past security'> error: 'not authorized'> you:'got past security'> ... etc ...