基于 Node.js 的消息传递框架 - Messenger.js
jopen
13年前
Messenger.js 是一个基于 Node.js 的消息传递框架,使用 JSON 格式传输数据,特点是简单而且快速。
Messenger.js 非常灵活,可以处理你所有全部需求:
- Supports Request / Reply Communication using round robin
- Supports Publish / Subscribe (fanout) Communication
- Supports Fire and Forget Communication
- Supports middleware plugin for messenger Listeners (servers)
- Extremely fast (disables TCP Nagle's algorithm)
- Fault tolerant: clients will reconnect to servers even if server goes down and comes back later
- Elegant API
- Easily involves multiple servers
示例代码:
var messenger = require('messenger'); client = messenger.createSpeaker(8000); server = messenger.createListener(8000); server.on('give it to me', function(message, data){ message.reply({'you':'got it'}) }); setInterval(function(){ client.request('give it to me', {hello:'world'}, function(data){ console.log(data); }); }, 1000);