1

I want to use nodejs server to receive messages from AMQP, then push those messages to web page through socket.io with redis.

The emit() function is invoked in the callback function consume of AMQP, and web UI can get those data. However, I can NOT find any data in redis?

codes

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...");
    });
});

call back function in AMQP

function response(msg){
    io.to('room').emit('online', msg);
}

...

ch.consume(queue, response, {noAck: true});

Am I right to use this API emit()? or miss any good trick?

zangw
  • 43,869
  • 19
  • 177
  • 214

0 Answers0