I'm receiving duplicate messages in my clustered node.js/socket.io/redis pub/sub application

后端 未结 2 2002
旧巷少年郎
旧巷少年郎 2021-02-04 18:02

I\'m using Node.js, Socket.io with Redisstore, Cluster from the Socket.io guys, and Redis.

I\'ve have a pub/sub application that works well on just one Node.js node. But

2条回答
  •  天涯浪人
    2021-02-04 18:37

    Turns out this isn't a problem with Node.js/Socket.io, I was just going about it the completely wrong way.

    Not only was I publishing into the Redis server from outside the Node/Socket stack, I was still directly subscribed to the Redis channel. On both ends of the pub/sub situation I was bypassing the "Socket.io cluster with Redis Store on the back end" goodness.

    So, I created a little app (with Node.js/Socket.io/Express) that took messages from my Rails app and 'announced' them into a Socket.io room using the socket.io-announce module. Now, by using Socket.io routing magic, each node worker would only get and send messages to browsers connected to them directly. In other words, no more duplicate messages since both the pub and sub happened within the Node.js/Socket.io stack.

    After I get my code cleaned up I'll put an example up on a github somewhere.

提交回复
热议问题