Skip to content

andresayak/nestjs-microservices-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Microservices with NestJS example

Microservices with NestJS: RabbitMQ, Redis, and Docker Compose Example

Description

This project demonstrates how to work with microservices using NestJS, RabbitMQ, Redis, and Docker Compose. It consists of three NestJS containers, one for the Swagger API documentation and a simple endpoint to create tasks and send them to RabbitMQ. The service_a container contains a microservice that implements the command businessCase1 in an imperative style. The service_b container contains a microservice that implements the commands checkApproved, approve, getBalance, feed, sign, send. In the example, the app container calls the businessCase1 command, and businessCase1 calls commands (checkApproved, approve, getBalance, feed, sign, send) sequentially. Before invoking a subcommand, the script checks whether the result of that command's execution is present in the cache. This is done for fault tolerance. If a task fails to execute completely for some reason, it will be restarted. If the subtasks have already been executed, it skips their execution and retrieves the results from the cache. The cache is stored in Redis, and after a successful task execution, the cache is cleared. All containers are launched using Docker Compose.

Installation

  1. To run this project locally, please follow the instructions below:
git clone git@github.com:andresayak/nestjs-microservices-example.git
  1. Navigate to the project directory:
cd nestjs-microservices-example
  1. Create a .env file in the root directory of the project and set the following environment variables:
RABBITMQ_QUEUE_NAME=test-subscribers
RABBITMQ_USER=guest
RABBITMQ_PASS=guest
RABBITMQ_VHOST=test

Usage

  1. Start the Docker containers using Docker Compose:
   docker-compose up
  1. Once the containers are up and running, you can access the Swagger API documentation at http://localhost. This endpoint allows you to create tasks and send them to RabbitMQ.
  2. The microservice with the implementation of the test1, test2, and test3 commands will be available for communication through RabbitMQ. You can interact with it programmatically or via the Swagger API.

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! If you find any issues or want to enhance the project, feel free to open a pull request.

Contact

If you have any questions or suggestions, please feel free to reach out to the project maintainer: Thank you for using this project!

I hope it helps you understand microservices with NestJS, RabbitMQ, and Redis using Docker Compose.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published