This is a microservices project for the management of orders and products using .NET 7.0.
Each entity is handled by a dedicated service, developed as a Worker Service.
Then, a ASP.NET Core REST API project is acting as a Gateway, enabling communication between the external world and the services.
The API and microservices communicate via JSON messages over an RPC channel using RabbitMQ.
- An external client queries the API.
- The API receives the request and places it in the appropriate queue managed by RabbitMQ.
- Each service has a worker listening on its respective queue to receive the request. In services I'm using Mediatr to decouple worker concepts and business logics.
- The request is sent via Mediatr, which invokes the CommandHandler.
- The CommandHandler processes the request by interacting with the database through EntityFramework.
- The CommandHandler returns the response, which then follows the same steps in reverse until it reaches the API.
It's the shared library where I've implemented the use of RabbitMQ. It exposes an IRPCClient interface and an IRPCServer interface that allow decoupling the other components of the project from RabbitMQ.
Contain models, commands, and DTOs shared between the various projects.
Other features that could be implemented:
- Data validation: entities don't have many attributes to validate, but in a real system, validation should be implemented, such as FluentValidation.
- Distributed transactions: there are some shared references between different entities. To ensure data integrity, a distributed transaction system could be implemented, such as the Saga Pattern.
- Automapper: conversion code between Entities ad Dto should be automated with Automapper.
The solution uses RabbitMQ for queue management. There are various solutions possible, I have used the following Docker command to start a pre-configured container:
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.12-management
To open RabbitMQ web console
- Url: http://localhost:15672/#/
- Username: guest
- Password: guest
To test the project you have to run:
- OrderSystemAPI
- OrderService
- ProductService