This project, bmb.production, is the production/kds microservice for a fast food application. It provides a simple API that allows users to see which orders need to be prepared and update its statuses and they move through the manufacturing pipeline. Additionally, it integrates with other domain microservices through messaging using MassTransit.
The terraform modules create a redis instance as part of the infrastructure. The decision to go with redis is based on the usage of this particular microservice. It will have a higher load of requests and the responses needs to be the closest to realtime, so users can see their orders status updates.
It uses Masstransit to manage communication between services. Masstransit automatically creates Topics, Queues and Subscriptions.
- Subscribes to
OrderCreated
events. - Adds the order to the orders list using the order ID as the key.
- Subscribes to
OrderPaymentConfirmed
events. - If the orders list contains the received OrderId:
- Adds
TrackingCode:OrderId
to theReceived
queue.
- Adds
- Received: Queue for orders that have been received.
- InPreparation: Queue for orders that are currently being prepared.
- Ready: Queue for orders that are ready for pickup or delivery.
- Endpoint: Lists all orders.
- Response Object:
{
"received": [
{
"orderId": "b39c3d69-2e43-47df-8b86-0037975ae211",
"code": "ASD-12"
}
],
"inPreparation":[
{
"orderId": "b33c3d69-2e43-47df-8b86-0037975ae211",
"code": "ASD-12"
}
],
"ready": [
{
"orderId": "c39c3d69-2e43-47df-8b86-0037975ae211",
"code": "ASD-22"
}
],
}
- Endpoint: Updates the status of an order.
- Request Parameters:
trackingCode
: The tracking code of the order.status
: The new status of the order. Valid statuses areInPreparation
,Ready
, orCompleted
.
- Status Change Rules:
- Status transitions must follow the sequence:
Received
->InPreparation
->Ready
->Completed
. - Status changes cannot be rolled back.
- If the order status is
Completed
, it should be removed from the orders list.
- Status transitions must follow the sequence:
- Events:
- An
OrderStatusChanged
event should be triggered on every status change operation.
- An
- Trigger: Executed from the
OrderPaymentConfirmed
event. - Actions:
- Adds the order to the
Received
queue. - Publishes an
OrderStatusChanged
event with the status valueReceived
.
- Adds the order to the
- Trigger: Executed when an order needs to be prepared.
- Actions:
- Removes the order from the
Received
queue. - Adds the order to the
InPreparation
queue. - Publishes an
OrderStatusChanged
event with the status valueInPreparation
.
- Removes the order from the
- Trigger: Executed when an order preparation is finished.
- Actions:
- Removes the order from the
InPreparation
queue. - Adds the order to the
Ready
queue. - Publishes an
OrderStatusChanged
event with the status valueReady
.
- Removes the order from the
- Trigger: Executed when an order is completed.
- Actions:
- Removes the order from the
Ready
queue. - Removes the order from the list.
- Publishes an
OrderStatusChanged
event with the status valueCompleted
.
- Removes the order from the