A simple example project on how to create and communicate with microservices using AspNetCore.
- AspNetCore 9.0
- Docker
- Docker Compose
- Apache Kafka (Confluent)
- Entity Framework Core
- PostgreSQL
- Clone the repository & install the dependencies:
git clone https://github.com/dagweg/Microservices.AspNetCore.git
dotnet restore
pnpm install .\microservices.client
- Make sure you have Docker Desktop installed.
- Run Zookeeper and Kafka using Docker Compose on the file
kafka.yml
:
docker-compose -f .\Microservices.AspNetCore.AppHost\kafka.yml up -d
- While this is running, run the Aspire API project:
dotnet watch run --project .\Microservices.AspNetCore.AppHost\
- Run the Next.Js Client
pnpm dev .\microservices.client
Test the project by placing product orders and observing the value after a few seconds.
- Input a quantity and place an order.
- This makes a POST request to the API, which publishes a message to the Kafka Broker.
- The Product-Microservice has event-handlers running in the background that continually listen to
OrderPlacedEvent
. When it receives an event, it checks the stock quantity and updates the stock. Otherwise it produces an 'OrderRejectedEvent'. - The Order-Microservice listens to either 'OrderCreatedEvent' or 'OrderRejectedEvent' and updates the order status accordingly.
- Finally, the client updates the new stock.