FAQ
Hi,

I'm working in realtime posts using socket.io,

Stream is updating realtime but the problem is redis subscription happens
multiple times and the post appears multiple times in the stream.

I'm using node.js cluster module to create multiple node clusters. Here is
the code,

*worker.js*

var cluster = require('cluster');var server = new Hapi.Server(config.port,view_options);
var socketIO = require('socket.io');var redis = require("socket.io/node_modules/redis");var RedisStore = require('socket.io/lib/stores/redis');
var io = socketIO.listen(server.listener);var sub = redis.createClient();
sub.setMaxListeners(0);

io.configure(function() {
     io.set('store', new RedisStore({
         redisSub : sub
     }));
     io.set('transports', ['xhr-polling']);
     io.set('polling duration', '10');});
if (cluster.isMaster) {
      for (var i = 0; i < numCPUs; i++) {
         cluster.fork();
     }} else {
     sub.subscribe("userstreams");
     io.sockets.on('connection', function(socket) {
     // Realtime streams : subscribe to redis channel userstreams
         sub.on("message", function(channel, member_postid) {
             console.info("-----------realtime post receieved --------",member_postid);
         });
     });}


*publisher.js*

// headvar redis = require("socket.io/node_modules/redis");var pub = redis.createClient();// inside a funtion
pst = member + "::" + data.pid
pub.publish("userstreams", pst);

The client publishes the postID only once but I'm getting multiple subscriptions in the userstreams channel in server.

I want my server to get the redis subscription only once so that I can send them in socket to a user's stream only once.

Any idea where i'm going wrong?

P.S.

I have also added this as a Stackoverflow <http://stackoverflow.com/questions/23220034/redis-subscribes-multiple-times-when-using-node-cluster-socket-io> question


Thanks,

Srikanth

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Yuri Karadzhov at Apr 26, 2014 at 10:21 am
    You need to configure pub, sub and client for socket.io:

    var pub = redis.createClient();
    var sub = redis.createClient();
    var client = redis.createClient();

    and pass them to socket.io

    io.set('store', new io.RedisStore({
       redisSub : sub,
       redisPub: pub,
       redisClient: client
    }));


    --
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Duy Nguyen at Apr 26, 2014 at 1:26 pm
    As Yuri said, you need to configure socket.io to use redis pubsub first.

    One alternative is that you should use built-in module such as
    https://github.com/topcloud/socketcluster, I saves your time and help you
    avoid un-expecting troubles.

    On Sat, Apr 26, 2014 at 5:21 PM, Yuri Karadzhov wrote:

    You need to configure pub, sub and client for socket.io:

    var pub = redis.createClient();
    var sub = redis.createClient();
    var client = redis.createClient();

    and pass them to socket.io

    io.set('store', new io.RedisStore({
    redisSub : sub,
    redisPub: pub,
    redisClient: client
    }));


    --
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

    ---
    You received this message because you are subscribed to the Google Groups
    "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to nodejs+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.


    --
    Nguyen Hai Duy
    Mobile : 0914 72 1900
    Skype: nguyenhd2107
    Yahoo: nguyenhd_lucky

    --
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedApr 25, '14 at 9:12a
activeApr 26, '14 at 1:26p
posts3
users3
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase