The idea here is to decentralize, do a load balancing .
In the following scenario:
.1 a website serving multiple subdomains with Nginx
.2 two or more servers nodejs
running socket.io
My need with nodejs
is to keep a server for messages and others for example: advertisements, applications, tools.
Most of the channels I searched for answers told me that the business is to keep everything in one o. ? But if there is a fatal error in tools for example it will end up knocking down everything (apps, ads, chat).
Officially Socket.IO does not help much and its documentation using-multiple-nodes and the closest I came to have an understanding was through this tutorial deploy-multiple-node-js-socket-io-servers-with-nginx-and-ssl
But although the idea is decentralized anyway, I still need to have socket.io
or sockets based on the point of origin in this case a rom strong> specifies.
I read in some reviews that this could be done with Redis
but Redis
is not an alternative for me because I'm using MongoDB
so I found this: socket.io-mongodb which does the same thing as it would with Redis
.
Following this logic any page HTML
would need to read javascript
of socket.io
(regardless of socket server) eg:
<script type="text/javascript" src="//localhost:9000/socket.io/socket.io.js"></script>
And in%% of pages I would have something like:
//para mensagens
var msg = io.connect('//localhost:9000');
// para o servidor de propagandas
var ads = io.connect('//localhost:7001');
// para o servidor de ferramentas
var tool = io.connect('//localhost:8001');