基于 Node.js 的流消息队列系统:Wormhole

pleo 11年前

Wormhole 是一个基于 Node.js 的流消息队列系统。其特点是高性能。

示例代码:

var Wormhole = require('wormhole');    net.createServer(function (client) {      Wormhole(client, 'chat', function (msg) {          // All messages received from client over chat channel, such as          // {hello: 'World'}      });        Wormhole(client, 'auth', function (msg) {          // All messages received from client, such as          // {hello: 'World'}          if (msg.user == 'foo' && msg.pass == 'bar') {             client.write('auth', {auth: 'Thank you for logging in'});          }      });        // client.write now overloaded to encode data.      client.write('auth', {auth: 'Please login!'});      client.write('chat', {greet: 'Welcome to our server!'});  }).listen(2122);  var client = net.createConnection(2122, function() {      Wormhole(client, 'chat', function (err, msg) {          // Messages received from server, such as          // {greet: 'Welcome to our server!'}      });      Wormhole(client, 'auth', function (err, msg) {          // Messages received from server on auth channel, such as          // {auth: 'Please login!'}          // {auth: 'Thank you for logging in!'}      });      client.write('auth', {user: 'foo', pass: 'bar'});      client.write('chat', {hello: 'World'});  });

项目主页:http://www.open-open.com/lib/view/home/1371963864150