1

我想使用nodejs服务器接收来自 的消息,然后通过withAMQP将这些消息推送到网页。socket.ioredis

emit()函数在 AMQP 的回调函数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});

我可以使用这个 APIemit()吗?或错过任何好把戏?

4

0 回答 0