3
votes

I am using redis for notification and it works like this -

When user1 has a notification to share with his friends, I publish that message to all channels of each friend of the user. Using socket.io and node, message is pushed to each friend as subscription part is handled using node.

This works fine until connection is lost. At this time, on reconnect, I am finding instead of 1, 2 publishes are happening to friend's channels although only 1 activity happened like last case..

Is their any config using which duplicate publish can be avoided on reconnect ?

Also finding, on reconnect it is trying to connect using secondary transports as well .. Can this be issue ?

1
I tried it, it is not yet solved .. - fortm
Have you found any solution? - Maziyar
Same problem here. Every reconnect adds 1 extra message per .emit() - Xeos
using jquery "once" solved it .. - fortm

1 Answers

1
votes

I suppose that on each connection

io.sockets.on('connection', function(client){
//...
});

you subscribe to redis

redisClient.subscribe('activity:*');

There is no need to connect to redis each time. You should connect to redis just before socket connection.