Skip to content

Pub Sub + Singleton (Implementation)

Course: Singleton Pattern, Backend State management and Pub Subs - chapter 6

  • 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

  • Init a simple node.js project
npm init -y
npx tsc --init
npm install redis
Create the Pub Sub Manager
$1b
Create a simple index.ts file to simulate users
import { PubSubManager } from "./PubSubManager";
setInterval(() => {
PubSubManager.getInstance().userSubscribe(Math.random().toString(), "APPL");
}, 5000)