I've been searching around looking for help on setting up a multi-server cluster for a Node.js Socket.IO install. This is what I am trying to do:
- Have 1 VIP in an F5 loadbalancer, pointing to
nnumber of Node servers running Express, and Socket.IO - Have client connect to that 1 VIP via
io.connectand then have it filter to one the of the servers behind the loadbalancer. - When a message is emitted on any one of those servers, it is is sent to all users who are listening for that event and connect via the other servers.
For example - if we have Server A, Server B and Server C behind LB1 (F5), and User A is connected to Server A, User B is connected to Server B and User C is connected to Server C.
In a "chat" scenario - basically if a message is emitted from Server A to message event - Server B and C should also send the message to their connected client. I read that this is possible with using socket-io.redis, but it needs a Redis box - which server should that be install on? If all the servers are connected to the same Redis box - does this work automatically?
var io = require('socket.io')(server);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
Any help would be greatly appreciated thanks!
socket.io-redisadapter will indeed automatically (with some configuration) achieve what you're looking for. It does not matter which node your Redis server will listen on, as long as all of the Socket.IO instances are subscribed to it. - hexacyanide