Wormhole JS流消息队列系统
Wormhole 是一个基于 Node.js 的流消息队列系统。其特点是高性能。和 Kafka 以及 Databus 类似,Wormhole 是个高度可扩展的发布/订阅系统。在 Facebook 内部,Wormhole 每天处理多达 1T 的消息,高峰时每秒超过 1 千万条消息。
Wormhole 总体架构如下图:
示例代码:
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'}); });
评论