Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to emit events in callback function? #52

Closed
richzw opened this issue Feb 3, 2015 · 1 comment
Closed

How to emit events in callback function? #52

richzw opened this issue Feb 3, 2015 · 1 comment

Comments

@richzw
Copy link

richzw commented Feb 3, 2015

Here is my case: nodejs server receives messages from AMQP, then push those messages to UI through socket.io-redis.

I try to call emit() function in the callback of AMQP, it works well. However, I can NOT find data in redis server?

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

callback 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 any other API?

@richzw richzw changed the title How to emit data in callback function? How to emit events in callback function? Feb 4, 2015
@darrachequesne
Copy link
Member

Closed due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants