agent.io

the package will be removed

Real-time, scalable agent<->server messaging

npm install agent.io
1 downloads in the last day
44 downloads in the last week
168 downloads in the last month

Agent.io - Real-time, scalable agent<->server messaging for Node.js

Agent.io is a simple long polling based Node.js messaging library. It is usefull for use cases, where agents having no inbound access have to talk to servers in both directions in real-time.

The server part currently relies on Express and Redis. Redis pubsub is used to enable scaling out of servers to serve more agents. Please make sure Redis library is installed npm install redis. Redis >= 2.6 is recommended if multiple servers are used.

I might add WebSocket transport at some point if it is proved to be well supported and reliable for server to server use cases.

Installation and Usage

Install Agent.io with npm both on client and server

npm install agent.io 

Agent-side usage

var agentio = require('agent.io');

/* if no group name is specified, a unique id will be assigned to the agent */
var agent = agentio.createClient({group: 'group1', server: 'http://localhost:3000'});

/* listener for messages, which server sends to "group1" */
agent.on('message', function(msg) {
});

/* sending a message to the server */
agent.send({field: "value"});

Server-side usage

/* agent.io */

var agentio = require('agent.io');

var server = agentio.createServer();

/* group1 message listener */
server.on('group1', function(msg) {
});

/* listener for messages from all groups */
server.on('message', function(group, msg) {
});

/* listener for messages from all groups. Returns an array of all 
 * messages sent during one second or single event loop cycle.
 */
server.on('messages', function(group, msgs) {
});


/* sending a message to agent */
server.send('group1', {field: "value"});



/* express app */

var express = require('express');
var app = express.createServer();

app.configure(function(){
  app.use(express.methodOverride());
  app.use(express.bodyParser());
  app.use(server.middleware()); // agent.io server
});

app.get('/', function(req, res){
  res.send('Hello World');
});

app.listen(3000);

License

Copyright (c) 2012 Dmitri Melikyan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you