An order-processing backend that uses RabbitMQ to handle orders asynchronously. The API stores an order in MongoDB, publishes an event to a queue and returns immediately; a background consumer then reserves stock and updates the order status.
POST /api/Order
│
├─► MongoDB: order saved as Pending
├─► RabbitMQ: OrderCreateEvent published to "order-created-queue"
└─► 201 Created returned to the client
OrderProcessingConsumer (BackgroundService)
├─ stock available → stock decremented, order → Completed
├─ stock insufficient → order → Cancelled
└─ processing error → message nacked → dead-letter queue
Highlights:
- Atomic stock reservation – the stock check and decrement happen in a single
FindOneAndUpdatewith aQuantityInStock >= amountfilter, so concurrent orders cannot oversell a product. - Dead-letter handling – failed messages are routed through a DLX (
order-dlx) toorder-dead-letter-queueinstead of being lost. - Manual acknowledgements with
prefetchCount = 1. - Correlation ID generated per request and carried through the message properties and logs.
- RabbitMQ.Client v7 with the fully async API.
- Backend: ASP.NET Core (.NET 9), MongoDB.Driver, RabbitMQ.Client, Swagger
- Frontend: Angular + Tailwind CSS
- CI: GitHub Actions (build)
1. Start MongoDB and RabbitMQ
docker run -d --name mongodb -p 27017:27017 mongo
docker run -d --name rabbitmq-server -p 5672:5672 -p 15672:15672 rabbitmq:3-managementRabbitMQ management UI: http://localhost:15672 (guest / guest)
2. Create MongoRabbitA/appsettings.json
{
"MongoDB": {
"ConnectionString": "mongodb://localhost:27017",
"DatabaseName": "productdb",
"OrderDatabase": "orderdb"
},
"RabbitMQ": {
"HostName": "localhost"
},
"AllowedHosts": "*"
}3. Run the API
cd MongoRabbitA
dotnet runSwagger UI: http://localhost:5035/swagger. The product collection is seeded from Data/Seed/products.json on first start.
4. Run the frontend
cd front-end
npm install
npm start| Method | Endpoint | Description |
|---|---|---|
| GET | /api/Product |
List products (paged) |
| GET | /api/Product/{id} |
Get product by id |
| GET | /api/Product/in-stock |
Products with stock > 0 |
| GET | /api/Product/brand/{brand} |
Products by brand |
| POST | /api/Product |
Create product |
| POST | /api/Product/bulk |
Create multiple products |
| PUT | /api/Product/{id} |
Update product |
| PATCH | /api/Product/{id}/stock |
Adjust stock |
| DELETE | /api/Product/{id} |
Delete product |
| GET | /api/Order |
List orders |
| GET | /api/Order/correlation/{correlationId} |
Get order by correlation id |
| POST | /api/Order |
Create order (processed asynchronously) |
- Docker Compose for the full stack
- Persistent messages and a long-lived publisher connection
- Retry with backoff and idempotent message handling
- Outbox pattern for reliable publishing
- Checkout and live order status in the Angular frontend
- Integration tests in CI