Reputation: 8588
I know their are a lot of questions and answers about this issue on the net but I can't get it to work.
I have a server written in node.js
and listening to connections with socket.io
Now, The sockets can exchange messages between them, like a chat and I'm broadcasting the incoming messages to all other sockets on the server.
I want to run my node
server on 3 different servers, each one of them have different IP, Lets call them: SERVER1
, SERVER2
and SERVER3
.
Here comes my confusion, if i'm sending a message from a socket which connected to SERVER1
, How the sockets that connected to SERVER2
and SERVER3
will see this message?
I heard about RedisStore
, RabbitMQ
and other stuff but i can't find a good article/post/book that can explain me how to do it right...
Can someone help me please?
Upvotes: 2
Views: 3595
Reputation: 63683
I believe RedisStore does this automatically for you, here's a good post about it: http://www.ranu.com.ar/2011/11/redisstore-and-rooms-with-socketio.html
How is this done internally?
Well as you have heard, Redis, RabbitMQ, ZeroMQ etc have pub-sub functionality, meaning you can subscribe to channels and publish info on them (to all the connected peers):
https://github.com/mranney/node_redis#publish--subscribe
So server A, B and C are subscribed to the same channel. When a client connected to server A wants to send a message for all the users connected to the chat room "js" for example, he sends a message to the server A and server A publishes a message on the "js" channel. All the rest of the servers get that message and broadcast it to all their clients.
Upvotes: 4