A simple order processing example built with ASP.NET Core (API) and a background worker service that processes order-placed messages from RabbitMQ. The repo contains:
OrderProcessingSystem.Api— REST API (Products, Cart, Orders, Authentication).OrderProcessingSystem.OrderPlacedService— background consumer (reads messages from RabbitMQ and sends email/log).docker-compose.ymlto run everything (API, consumer, SQL Server, RabbitMQ, Seq).
- Quick start (Docker)
- Prerequisites
- Ports & services
- Environment / configuration
- Run locally (dev)
- API overview (endpoints)
- Background worker
- Database & migrations
- Notes & TODOs
- Contact / next steps
- From repository root run:
docker compose up --buildThis will build and start the API service, the background consumer, RabbitMQ, SQL Server and Seq as defined in docker-compose.yml.
- Open API swagger (when container healthy):
- API is exposed inside containers on ports
8080/8081and mapped to host ports5001/5002indocker-compose.yml. Checkhttp://localhost:5001/swagger(orhttps://localhost:5002/swagger) depending on your environment.
- API is exposed inside containers on ports
- Docker & Docker Compose (Docker Desktop or Docker Engine with Compose V2).
- (Optional) .NET 8 SDK if you want to run projects locally without containers.
- API: host
5001-> container8080(and5002->8081). - Consumer worker: host
6001/6002mapped to worker ports. - SQL Server:
1433(container usesmcr.microsoft.com/mssql/server:2022-latest). - RabbitMQ management:
15672, broker port:5672. - Seq (logging UI):
9090.
Configuration lives in each project appsettings.json and is also injected via docker-compose.yml environment variables.
Important example settings:
- Connection string (SQL Server) — set in API
appsettings.jsonand overridden from docker-compose:ConnectionStrings__DefaultConnection. - JWT signing key (API): set in
OrderProcessingSystem.Api/appsettings.jsonunderJwt:Key. - RabbitMQ config:
RabbitMQ:Host,RabbitMQ:User,RabbitMQ:Pass(used by API and worker). Defaults point to therabbitmqservice indocker-compose.yml. - Email sender (consumer):
OrderProcessingSystem.OrderPlacedService/appsettings.jsoncontainsEmailSendercredentials used by the worker to send notification emails. Replace with secure values.
- Ensure you have a SQL Server instance and RabbitMQ accessible.
- Update
OrderProcessingSystem.Api/appsettings.jsonconnection string andRabbitMQsettings to point to your services. - From
OrderProcessingSystem.Apirun:
dotnet restore
dotnet build
dotnet run- For the worker service, run
OrderProcessingSystem.OrderPlacedServicesimilarly. The worker subscribes toorder_exchange/order_queueand processes messages.
Swagger is configured in
Program.csand exposes the routes. Authentication is JWT-based.
POST /api/Account/Register— register a user (body:RegisterUserRequestDto).POST /api/Account/Login— login and receive JWT (body:LoginUserRequestDto).
GET /api/Products— list products.GET /api/Products/{id}— get product by id.POST /api/Products— (Admin) create product.PUT /api/Products/{id}— (Admin) update product.DELETE /api/Products/{id}— (Admin) delete product.
GET /api/User/cart— get authenticated user's cart items.POST /api/User/cart— add item to authenticated user's cart.
POST /api/User/order— place order (uses user's cart items; sends message to RabbitMQ).- Admin endpoints (in
OrdersController) provide the ability to CRUD orders.
- When an order is placed, the API constructs and sends an
OrderPlacedMessageto RabbitMQ. The worker (OrderProcessingSystem.OrderPlacedService) consumes messages fromorder_queue, acknowledges them and sends an email (viaIEmailSender) or logs the result.
- EF Core migrations are present under
OrderProcessingSystem.Api/Migrations. The initial migration createsUsers,Products,Orders,OrderItems,CartItemstables with the indexes used by the app (unique cart item per user/product, unique order item per order/product).
If running locally, you can apply migrations with:
cd OrderProcessingSystem.Api
dotnet ef database update(Ensure dotnet-ef is installed and appsettings.json connection string points to your DB.)
- The
PlaceOrderflow has comments indicating planned improvements: stock quantity checks, transactional behavior, batch add/remove of order items, decrementing product stock when order placed. - Secrets (SQL SA password, JWT key, email creds) are currently in
docker-compose.ymlandappsettings.json. Do not keep these in a public repo — move them to secrets or environment variables for production.
Register:
curl -X POST http://localhost:5001/api/Account/Register -H "Content-Type: application/json" -d '{"FirstName":"John","LastName":"Doe","UserName":"johnd","Email":"john@example.com","Password":"P@ssw0rd","ConfirmPassword":"P@ssw0rd"}'Login:
curl -X POST http://localhost:5001/api/Account/Login -H "Content-Type: application/json" -d '{"Email":"john@example.com","Password":"P@ssw0rd"}'Use the returned JWT in Authorization: Bearer <token> for protected endpoints (cart, place order, admin endpoints).
docker-compose.yml— full service composition & envs.OrderProcessingSystem.Api/Program.cs— app startup, JWT, DI, Swagger.OrderProcessingSystem.Api/Controllers/*— controllers for Accounts, Products, Orders, Cart, User.OrderProcessingSystem.OrderPlacedService/Worker.cs— RabbitMQ consumer logic.OrderProcessingSystem.Api/Migrations/*— EF Core migrations.
- Add a Development section (run with Visual Studio / launch profiles).
- Implement the TODOs: transactional order placement and stock decrement.
- Add Postman collection or example requests.
- Sanitize secrets and add example
.envand.env.example.