Pub Sub + Singleton (Implementation)
Course: Singleton Pattern, Backend State management and Pub Subs - chapter 6
Starting the pub sub
Section titled “Starting the pub sub”- Start a pub sub (redis is a decent one)
docker run -d -p 6379:6379 redis- Try a simple publish subscribe in two terminals
docker exec -it d1da6bcf089f /bin/bash redis-cli
Creating the PubSubManager
Section titled “Creating the PubSubManager”- Init a simple node.js project
npm init -ynpx tsc --initnpm install redisCreate the Pub Sub Manager
$1bCreate a simple index.ts file to simulate users
import { PubSubManager } from "./PubSubManager";
setInterval(() => { PubSubManager.getInstance().userSubscribe(Math.random().toString(), "APPL");}, 5000)