我想使用nodejs
服务器接收来自AMQP
的邮件,然后使用socket.io
通过redis
将这些邮件推送到网页。
在AMQP的回调函数emit()
中调用consume
函数,并且Web UI可以获取这些数据。但是,我在redis
?
码
var redisPort = 6379,
redisHost = 'localhost';
var app = require('express')(),
http = require('http').Server(app),
io = require('socket.io')(http),
redisAdapter = require('socket.io-redis'),
redis = require('redis');
var
pub = redis.createClient(redisPort, redisHost),
sub = redis.createClient(redisPort, redisHost, {detect_buffers: true});
//
io.adapter( redisAdapter({pubClient: pub, subClient: sub}) );
app.get('/', function(req, res){
res.sendFile('index.html');
});
io.on('connection', function(socket){
console.log("web socket connection ...");
socket.join('room');
socket.on('disconnect', function(){
console.log("socketio diconnect...");
});
});
回调AMQP
function response(msg){
io.to('room').emit('online', msg);
}
...
ch.consume(queue, response, {noAck: true});
我是否正确使用此API emit()
?或者错过任何好招?