Wormhole JS流消息隊(duì)列系統(tǒng)
Wormhole 是一個(gè)基于 Node.js 的流消息隊(duì)列系統(tǒng)。其特點(diǎn)是高性能。和 Kafka 以及 Databus 類似,Wormhole 是個(gè)高度可擴(kuò)展的發(fā)布/訂閱系統(tǒng)。在 Facebook 內(nèi)部,Wormhole 每天處理多達(dá) 1T 的消息,高峰時(shí)每秒超過 1 千萬條消息。
Wormhole 總體架構(gòu)如下圖:
示例代碼:
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'});
});評(píng)論
圖片
表情
