{"id":23651331,"url":"https://github.com/damiancipolat/nodejs-message-send-study","last_synced_at":"2026-04-26T20:32:28.917Z","repository":{"id":139320624,"uuid":"171605935","full_name":"damiancipolat/Nodejs-message-send-study","owner":"damiancipolat","description":"In this project I analyze different ways to create a distributed message processing backend using Node.js and sockets","archived":false,"fork":false,"pushed_at":"2019-03-30T04:50:32.000Z","size":918,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-20T01:13:29.411Z","etag":null,"topics":["balancer","load","nodejs","socketio","sockets"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damiancipolat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-20T05:18:00.000Z","updated_at":"2019-03-30T04:50:34.000Z","dependencies_parsed_at":"2023-03-18T08:16:08.309Z","dependency_job_id":null,"html_url":"https://github.com/damiancipolat/Nodejs-message-send-study","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/damiancipolat/Nodejs-message-send-study","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FNodejs-message-send-study","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FNodejs-message-send-study/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FNodejs-message-send-study/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FNodejs-message-send-study/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damiancipolat","download_url":"https://codeload.github.com/damiancipolat/Nodejs-message-send-study/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damiancipolat%2FNodejs-message-send-study/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32312314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T19:15:34.056Z","status":"ssl_error","status_checked_at":"2026-04-26T19:15:15.467Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["balancer","load","nodejs","socketio","sockets"],"created_at":"2024-12-28T16:37:08.240Z","updated_at":"2026-04-26T20:32:28.912Z","avatar_url":"https://github.com/damiancipolat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Message processor\nExamples and techniques of how to create a nodejs message processor through a permanent socket.\n\n**Chapter list:**\n\n- **[Model I]** simple client / server\n- **[Model II]** client / master-worker server\n- **[Model III]** client / master-worker server + custom socket balancer\n- **[Model IV]** client / master-worker server + NGINX\n\n[Model I]:https://github.com/damiancipolat/Node-MSG-Processor#model-i\n[Model II]:https://github.com/damiancipolat/Node-MSG-Processor#model-2\n[Model III]:https://github.com/damiancipolat/Node-MSG-Processor#model-3\n[Model IV]:https://github.com/damiancipolat/Node-MSG-Processor#model-4\n\n## Model I:\nA single process with a server that receive and process the messages.\n\n**Stress test:**\nProcess done with 3k messages.\n\n![N|Solid](https://github.com/damiancipolat/Node-MSG-Processor/blob/master/doc/doc-1.png?raw=true)\n\n**To run:**\n```js\n$ cd model-1\n$ npm install\n$ npm start\n```\n\n## Model 2:\nA single process with a server that receive and process the messages.\n\n**Stress test:**\nProcess done with 6k messages.\n\n![N|Solid](https://github.com/damiancipolat/Node-MSG-Processor/blob/master/doc/doc-2.png?raw=true)\n\n**To run:**\n```js\n$ cd model-2\n$ npm install\n$ npm run server\n$ npm run client\n```\n\n## Model 3:\nA model defined, that is ready to scale horizontal. This model use the model II with a load balancer in the front, this module have a particular beahaviour, function as an apirest that return a url of one server that is defined in his server list.\n\n**Stress test:**\nProcess done with 10k messages.\n\n![N|Solid](https://github.com/damiancipolat/Node-MSG-Processor/blob/master/doc/doc-3.png?raw=true)\n\n**To run:**\n```js\n$ cd model-3\n#To start server in a port.\n$ npm run server 8080\n\n#To start client, define server url and amount of request.\n$ npm run client 100 http://localhost:8080\n```\n\n### Using custom socket balancer:\n\n![N|Solid](https://github.com/damiancipolat/Node-MSG-Processor/blob/master/doc/doc-4.png?raw=true)\n\n**To run:**\n```js\n$ cd model-3\n#To start client\n$ npm run client\n\n#To start server\n$ npm run server\n\n#To start balancer\n$ npm run balancer\n```\n## Model 4:\n**Using NGINX as socket balancer**, This show how to use NGINX as socket load balancer. In productive environemts, I thinks that use NGINX is the best option instead of use my example of the previouse example, because is a very eficient and confiable product so is a good option to use in every project. \n\nI'm following this link: https://www.digitalocean.com/community/tutorials/how-to-develop-a-node-js-tcp-server-application-using-pm2-and-nginx-on-ubuntu-16-04\n\n### Diagram:\n![N|Solid](https://github.com/damiancipolat/Node-MSG-Processor/blob/master/doc/doc-5.png?raw=true)\n\n### Basic example: (client / NGINX /  Server) without load balancer.\nThis example create a Nodejs socket server listen connections in the port **8081** and set the NGINX in the middle receiving connections in the port 8000 and by pass them to the port 8081, for other hand there are a client process that sent data to nginx. Pleas thake a look at the file nginx.conf\n\n**nginx.conf**\n```js\n...\nstream {\n    server {\n      listen 8000;\n      proxy_pass 127.0.0.1:8081;\n      proxy_protocol on;\n    }\n}\n```\n\n**To run:**\n```js\n$ cd model-4/basic\n#To start server\n$ pm2 start server.js\n\n#To start nginx\n$ sudo systemctl restart nginx\n\n#To start client\n$ npm run client\n\n#To view process running\n$ pm2 list\n```\n\n#### Another configuration, could be /etc/nginx/sites-enabled/default\n```js\nserver {\n    listen 80;\n    server_name 127.0.0.1;\n\n    location / {\n        proxy_pass http://127.0.0.1:8081;\n        proxy_redirect off;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\n    }\n}\n```\n### NGINX as load balancer:\nI get the nginx configuration from: \n\nhttps://socket.io/docs/#using-with-node-http-server\n\nhttps://www.digitalocean.com/community/tutorials/how-to-develop-a-node-js-tcp-server-application-using-pm2-and-nginx-on-ubuntu-16-04\n\n#### Configuration /etc/nginx/nginx.conf\nTake care of set \"stream\" in nginx.conf.\n\n```js\nevents{\n  \n}\n\nstream {\n\n    # Load balancer configuration\n    upstream exampleApp {\n        # One failed response will take a server out of circulation for 20 seconds.\n        server  127.0.0.1:8081;\n        server  127.0.0.1:8082;\n        server  127.0.0.1:8083;\n    }\n\n    server {\n      listen 8000;\n      proxy_pass exampleApp;\n      proxy_protocol on;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamiancipolat%2Fnodejs-message-send-study","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamiancipolat%2Fnodejs-message-send-study","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamiancipolat%2Fnodejs-message-send-study/lists"}