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