In this demo, we will explore how to leverage the @tamimaj/nestjs-redis-streams package to use Redis Streams as a message broker within a NestJS-based microservice architecture. To illustrate the capabilities of this library, we will set up a simple scenario involving three components: an API Gateway, a Users Microservice, and a Notification Microservice.
- API Gateway: This component exposes a REST endpoint that simulates the creation of a new user.
- Users Microservice: It listens to a Redis Stream for incoming commands related to user creation. When a new user creation command is received, this microservice emulates the process of creating a user and publishes a response to a designated stream.
- Notification Microservice: This service is also interested in user creation responses. It listens to the user-created response stream and, upon receiving a response, simulates the action of sending a welcome email to the user.
Follow these steps to run the demo on your local machine:
Clone the demo repository from GitHub using the following command:
git clone https://github.com/tamimaj/nestjs-redis-streams-demo.git
Navigate to each of the services (API Gateway, Users Microservice, and Notification Microservice) and install the required dependencies using the following commands:
cd api-gateway
npm install
cd ..
cd users
npm install
cd ..
cd notification
npm install
cd ..