- Go 1.22.3
- RabbitMQ 3.13.6
- amqp091-go v1.10.0
- Handles the creation, updating, and retrieval of orders.
- Processes expired product reservations and payments.
- Manages product reservations and cancellations.
- Ensures that products are reserved for orders.
- Handles the cancellation of reservations if needed.
- Processes payments for orders.
- Handles the payment actions.
- Ensures that payments are completed or failed.
- order-action-exchange: Routes order-related action messages.
- order-result-exchange: Routes order-related result messages.
- dlx-exchange: Dead-letter exchange used to handle messages that cannot be processed.
- product-reservation-queue:
- Holds messages for product reservation actions.
- TTL: 15000 ms.
- Configured DLX: dlx-exchange.
- payment-queue:
- Holds messages for payment actions.
- TTL: 60000 ms.
- Configured DLX: dlx-exchange.
- product-reservation-result-queue: Holds messages for product reservation results.
- payment-result-queue: Holds messages for payment results.
- dlx-product-reservation-queue: Holds dead-letter messages for product reservation actions.
- dlx-payment-queue: Holds dead-letter messages for payment actions.
- Handle
POST /orders
request. - Create an order entity in the repository with status "Pending".
- Publish an
OrderAction
message toorder-action-exchange
with routing keyproduct-reservation-action-queue
. - Return the order response with status "Pending".
- Consume messages from
product-reservation-action-queue
inproduct-service
. - If the message expires, it will be routed to
dlx-exchange
with routing keydlx-product-reservation-action-queue
. order-service
will consume expired messages fromdlx-product-reservation-action-queue
and mark the order as failed.product-service
will process the reservation and publish anOrderActionResult
message toorder-result-exchange
with routing keyproduct-reservation-result-queue
.
- Consume messages from
product-reservation-result-queue
. - If the reservation is successful, publish an
OrderAction
message toorder-action-exchange
with routing keypayment-action-queue
. - If the reservation fails, mark the order as failed.
- Consume messages from
payment-action-queue
inpayment-service
. - If the message expires, it will be routed to
dlx-exchange
with routing keydlx-payment-action-queue
. order-service
will consume expired messages fromdlx-payment-action-queue
and mark the order as failed.payment-service
will process the payment and publish anOrderActionResult
message toorder-result-exchange
with routing keypayment-result-queue
.
- Consume messages from
payment-result-queue
. - If the payment is successful, mark the order as completed.
- If the payment fails, publish an
OrderAction
message toorder-action-exchange
with routing keyproduct-cancellation-action-queue
.
- Consume messages from
product-cancellation-action-queue
inproduct-service
to cancel the reservation.
- Handle
GET /orders/{id}
request to retrieve the order status.
Endpoint: POST /orders
Request Body:
{
"customerId": "123e4567-e89b-12d3-a456-426614174000",
"cardId": "123e4567-e89b-12d3-a456-426614174003",
"itemId": "123e4567-e89b-12d3-a456-426614174002",
"price": 100
}
Responses:
201 Created
{
"id": "ae5e5918-facb-40e5-bbdf-3525cedaaa7e",
"customerId": "123e4567-e89b-12d3-a456-426614174000",
"cardId": "123e4567-e89b-12d3-a456-426614174003",
"itemId": "123e4567-e89b-12d3-a456-426614174002",
"price": 100,
"status": "pending",
"message": "Order is pending"
}
400 Bad Request.
500 Internal Server Error.
Endpoint: GET /orders/{id}
Responses:
200 OK
{
"id": "ae5e5918-facb-40e5-bbdf-3525cedaaa7e",
"customerId": "123e4567-e89b-12d3-a456-426614174000",
"cardId": "123e4567-e89b-12d3-a456-426614174003",
"itemId": "123e4567-e89b-12d3-a456-426614174002",
"price": 100,
"status": "completed",
"message": "Order is completed"
}
404 Not Found.
500 Internal Server Error.