node.js - Redis Subscribes multiple times when using Node Cluster, Socket.io -


I am working in realtime posts using socket.io,

stream real time updates But the issue is re-subscribed to membership several times and the post appears several times in the stream.

I am using node.js cluster module to create multiple node groups. Here is the code,

worker.js

  var cluster = expected ('cluster'); var server = new happy Server (config.port, view_options); Var socketIO = is required ('socket.io'); Var redis = Required ("socket.io/node_modules/redis"); Var RedisStore = Required ('socket.io/lib/stores/redis'); Var io = socketIO.listen (server.listener); Var sub = redis.createClient (); Sub.setMaxListeners (0); Io.configure (io.set ('store', new redisstore ({redisSub: sub}); io.set ('transports', [' xhr-poll ']); io.set (' polling Duration ',' 10 ');}); if (cluster.isMaster) {for (var i = 0; i & lt; numCPUs; i ++) {cluster.fork ();}} and {sub.subscribe ("userstreams"); Io.sockets.on ('Connection', Function (socket) {// Realtime Stream: Subscribe to SubOn of Channel Userstream ("Message", Function (Channel, Member_postid) {console.info (" ----- ------ Real time rank received -------- ", member_postid);});})}}   

publisher.js // head var redis = need ("socket.io/node_modules/redis") var pub = redis.createClient (); // pst = member + "::" + data .pid.pubilish ("userstreams", pst) within a function;

The client publishes the post ID only once But I am getting multiple subscriptions in the userstream channel in the server

I want my server to be able to subscribe only once so that I can only send it to the user's stream in the socket once.

You must configure pub, all, and client for socket.io:

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

and assign them to socket.io

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

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -