带有redis存储的Socket.io在AMQP的回调函数消耗中发出事件

时间:2015-02-04 03:09:01

标签: node.js redis socket.io socket.io-redis

我想使用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()?或者错过任何好招?

0 个答案:

没有答案