This project demonstrates a microservices architecture using NestJS and BullMQ for job queue management.
- Node.js (v14 or later)
- Yarn
- Redis (or Docker running a Redis container)
-
Install dependencies:
yarn install
-
Start a local Redis server on the default port (6379), or use Docker to run a Redis container:
docker run --name redis -p 6379:6379 -d redis
This command will start a Redis container named "redis" and map the container's port 6379 to the host's port 6379.
-
Start Microservice A:
yarn start:a
-
In a new terminal, start Microservice B:
yarn start:b
Use the following API endpoints to trigger example jobs in Microservice A:
-
Add a default job:
curl -X POST http://localhost:3000/default-job
-
Add a not handled job:
curl -X POST http://localhost:3000/not-handled-job
-
Add a delayed job:
curl -X POST http://localhost:3000/delayed-job
-
Add a repeatable job:
curl -X POST http://localhost:3000/repeatable-job
Alternatively, you can use the provided REST Client file to trigger these jobs. The file is located at rest-client.rest
.
To use this file, you'll need to install the "REST Client" extension for Visual Studio Code. Once installed, you can open the rest-client.rest
file and use the "Send Request" link above each endpoint to easily trigger the jobs without leaving your editor.
Microservice B will process the jobs added by Microservice A. You can monitor the job processing in the console output of Microservice B.
-
Microservice A (Producer): Adds jobs to the queue
- Main file:
apps/microservice-a/src/main.ts
- Controller:
apps/microservice-a/src/microservice-a.controller.ts
- Producer:
apps/microservice-a/src/microservice-a.producer.ts
- Listener:
apps/microservice-a/src/microservice-a.listener.ts
- Main file:
-
Microservice B (Consumer): Processes jobs from the queue
- Main file:
apps/microservice-b/src/main.ts
- Consumer:
apps/microservice-b/src/microservice-b.consumer.ts
- Main file:
Both microservices are configured to use the local Redis server. You can modify the connection settings in the respective module files if needed.
For more details on the NestJS framework and its features, please refer to the NestJS documentation.