Skip to content

danillofratta/app-microservices-servicebus-dotnet-edd-cqrs-ddd-angular

Repository files navigation

Challenge

Create the option within the same project to use messaging with Rebus, MassTransit, or NServiceBus.

Objective

This project aims to demonstrate the implementation of the following technologies and architectural patterns:

  • API (.NET)
  • Patterns: DDD, EDD, CQRS
  • NServiceBus using Saga (RabbitMQ)
  • Redis
  • FluentValidation
  • MediatR
  • Entity Framework
  • Angular
  • PostgreSQL
  • Docker
  • ...

Project

The solution is composed of four services:

  • Product -- Simple product registration using Redis for caching.
  • Stock -- Simple service responsible for adding products to stock.
  • Sale -- Simple service responsible for creating a sale.

Process (using messaging via MassTransit, Rebus, or NServiceBus implemented with Saga):

  • Sends a message to the Stock service.

  • The Stock service checks whether the requested items are available in stock.

  • If available:

    • Sends a message to Sale indicating that stock is available.
    • Sends a message to Payment.
  • If not available:

    • Sends a message to Sale indicating stock failure.
    • Ends the process.
  • Payment simulates a payment result (success or failure). In both cases, it returns a message to Sale and ends the process.

  • Payment -- Simulates payment success or failure and sends a message to Sale.

  • Mini framework -- A small framework was created to support the messaging implementation.

Running the Application with Docker

  • Build the backend
    • Navigate to the folder src/backend/src and run:

      docker-compose up --build

  • Build the frontend
    • Navigate to the folder src/frontend/appclientangular and run:

      docker build -t app-client -f Dockerfile .

  • Run database migrations
    • Navigate to src/backend/src/Shared/Shared.Infrastructure and run:

      dotnet ef migrations add InitialCreate dotnet ef database update

  • Start the containers

Message Flow Between Endpoints

Message Flow

Switching the Messaging Framework

  1. In the WebApi projects (Sale, Stock, Payment) configure which messaging framework should be used. For example:

    • If using MassTransit, add a reference to: Stock.Infrastructure.MassTransit

    • If using Rebus, add a reference to: Stock.Infrastructure.Rebus

    • If using NServiceBus, add a reference to: Stock.Infrastructure.NServiceBus

  2. In appsettings.json, define which messaging framework should be used.

TODO

  1. Create an orchestrator to define which messaging framework should be used without needing to manually reference the project, or create separate workers and an orchestrator that selects the messaging system before starting the project.

Additional TODO

  • Create IoC container configuration
  • Add more queries using SignalR
  • Add other frontend technologies such as Blazor and Next.js
  • Improvement: the final solution would include specific workers for each messaging framework and an orchestrator responsible for selecting the messaging implementation

About

MVP App with DDD, CQRS, DDD architecture using 4 microservices and 3 types of servicebus (choose which one): rebus, masstransit, nservicebus. Mini decoupled architecture applying solid principles

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors