This project demonstrates a simple choreography-based workflow using the Saga pattern. The scenario involves creating orders with initial "Created" state and checking product availability before processing the order.
-
Create New Order:
- Create a new order with the state
CREATED.
- Create a new order with the state
-
Check Product Stock Availability:
- Check the stock availability of the product associated with the order.
-
Process Order:
- If the product is available, change the order state to
PROCESSING.
- If the product is available, change the order state to
-
Handle Out-of-Stock:
- If the product is out of stock, delete the order.
This choreography example implements the Saga pattern, which orchestrates a series of local transactions across multiple services to maintain consistency in a distributed system. Each step in the scenario represents a local transaction within a service, ensuring that the system remains consistent even in the face of failures or partial completion.
- API Gateway: Exposes endpoints for interaction.
- Eureka Service: Service registry for service discovery.
- Order Service: Manages orders and their states.
- Product Service: Handles product-related operations.
-
Clone the Repository:
git clone https://github.com/ELMILYASS/SAGA-Choreography-Kafka.git
-
Start Kafka:
Ensure Kafka is running locally. You can follow the Kafka documentation for installation and setup.
-
Build and Run Services:
- Navigate to each service directory (
api-gateway,eureka-service,order-service,product-service) and run it
- Navigate to each service directory (
-
Accessing Endpoints:
- API Gateway runs on port
9999. - Eureka Service runs on port
8761. - Order Service runs on port
8093. - Product Service runs on port
8094.
- API Gateway runs on port
-
View All Products:
GET http://localhost:9999/PRODUCT-SERVICE/AllProducts
-
Check Stock of a Product:
GET http://localhost:9999/PRODUCT-SERVICE/Stock/{prodId}/{qnt}
-
Create a New Order:
GET http://localhost:9999/ORDER-SERVICE/new/{prodId}/{qnt}
-
View Details of an Order:
GET http://localhost:9999/ORDER-SERVICE/{orderId}
-
View All Orders:
GET http://localhost:9999/ORDER-SERVICE/AllOrders