GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cmgchess/socketio-redis-pubsub-demo: Demo for Socket.IO Redis adapter using Nginx

BranchesTags
Open more actions menu

Latest commit

 

History

8 Commits
8 Commits

Folders and files

NameName
Last commit message
Last commit date
client
client
 
 
screenshots
screenshots
 
 
server
server
 
 
README.md
README.md
 
 

Repository files navigation

Prerequisites

  • Realtime Chat With Users & Rooms - Socket.io, Node & Express
  • REPO - bradtraversy/chatcord

Additional helpful resources

  • Scaling Websockets with Redis, HAProxy and Node JS - High-availability Group Chat Application
  • Load Balancing NodeJS applications using NginX
  • Socket.IO Docs - Using multiple nodes
  • Socket.IO Docs - Adapters
  • Socket.IO Docs - Redis adapter

Additional Tools

  • nginx
  • Redis
  • Node.js v14+
  • http-server

Here is a MSI installer I found for Redis.

Setup

  1. Clone repository
  2. cd into server and npm install

Nginx conf

http {

    upstream backend {
        hash '$remote_addr $cookie_zzz $http_user_agent';
	server 127.0.0.1:1212;
        server 127.0.0.1:1213;
    }
		
    server {
        listen 80;
	root E:\\socket\\server;

	location / {
            proxy_pass http://backend;
        }
    }
}

events { }

https://stackoverflow.com/questions/59124543/nginx-not-loadbalancing-in-case-of-ip-hash

Running client

  1. cd intoclient
  2. run http-server . --cors --port=5500

Running server

  1. cd into server and open 2 terminals for the same directory
  2. Set 2 different ports ( ex: export PORT=1212 in one terminal and export PORT=1213 in the other)
  3. Start nginx with the given configuration
  4. npm start the server on both terminals

Now Server 1 will be started on PORT=1212 and Server 2 on PORT=1213 and the Client on PORT=5500. Two servers will be load balanced using nginx on PORT=80 so the client will be directed to either Server 1 or 2 when it hits Port 80. Hash based load balancing is enabled (to achieve stickiness) since nginx open source doesn't allow cookie based load balancing. Go to http://127.0.0.1:5500/ with 2 browsers (Edge and Chrome for example) then the 2 instances will be connected to Server 1 and 2 respectively.
Redis will act as a PubSub mechanism and is enabled using Socket.IO Redis Adapter.
NOTE: Redis adapter will not store anything, it will only do PubSub.
If you want you can store data in Redis as well.

Architecture

User logged in Edge Browser User logged in Chrome Browser

About

Demo for Socket.IO Redis adapter using Nginx

Topics

nginxnode-redisnodejsredisredis-adaptersocket-iosocketio-redissticky-sessions

Resources

Readme
Activity

Stars

22 stars

Watchers

1 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.