A simple demonstration of the Message-based Architecture: Pub/Sub pattern using Node.js, Express, Redis, BullMQ, and Bull Board. This project illustrates how a publisher and a subscriber can communicate through a Redis-backed message queue system. The publisher sends tasks (messages) to the message queue, while the subscriber processes the tasks and sends the result back through a response queue. Additionally, Bull Board provides a web-based interface for monitoring both queues in real-time.
- Message Queue: Publisher adds jobs to a Redis-backed queue (via BullMQ).
- Response Queue: Subscriber processes jobs and sends completion notifications back to the publisher.
- Bull Board: Web interface to monitor and visualize the status of jobs and queues.
- Progress Tracking: Job progress updates every 3 seconds, showing 25%, 50%, 75%, and 100% progress over 12 seconds.
.
├── publisher.js # Publisher logic to send tasks and handle response queue
├── subscriber.js # Subscriber logic to process tasks and send responses
├── package.json # Project dependencies and metadata
├── .gitignore # Git ignore file to exclude node_modules
└── README.md # Documentation for the project
- Node.js (v14 or higher)
- Redis (v5 or higher)
- Node.js: Download from nodejs.org.
- Redis: Instructions below for different platforms.
- Download Redis for Windows from Microsoft's Redis Releases.
- Extract and run
redis-server.exe
.
Alternatively, you can use Windows Subsystem for Linux (WSL) to install Redis:
- Install WSL on your Windows machine (requires Windows 10 or higher).
- Install Redis:
sudo apt-get update sudo apt-get install redis-server
- Start Redis:
redis-server
- Download and install Node.js from https://nodejs.org/.
-
Linux:
sudo apt update sudo apt install redis-server
-
macOS (via Homebrew):
brew install redis
-
Start the Redis server:
redis-server
- Linux:
sudo apt update sudo apt install nodejs npm
- macOS (via Homebrew):
brew install node
-
Clone the repository:
git clone https://github.com/PeterWadie/PubSubDemo.git cd PubSubDemo
-
Install project dependencies:
npm install
Ensure the Redis server is running:
redis-server
In one terminal window, start the Publisher:
node publisher.js
The Publisher service will be running at http://localhost:3000
. Bull Board will be accessible at http://localhost:3000/admin
.
In another terminal window, start the Subscriber:
node subscriber.js
The Subscriber will start processing jobs from the message queue and will send completion notifications to the response queue.
You can add jobs to the message queue by navigating to the following URL in your browser:
http://localhost:3000/publish/<YourMessage>
For example, to publish a job with the message "HelloWorld", visit:
http://localhost:3000/publish/HelloWorld
As the subscriber processes jobs, you can observe the job's progress in the terminal where the subscriber is running. The job will update its progress every 3 seconds (25%, 50%, 75%, 100%).
Bull Board provides a web-based UI for monitoring jobs in the message queue and the response queue. To access the Bull Board:
-
Open your browser and navigate to:
http://localhost:3000/admin
-
You will see two queues:
- messageQueue: This is where new jobs are published by the publisher.
- responseQueue: This queue contains job completion notifications from the subscriber.
Bull Board updates every 3 seconds, showing job statuses and progress.