To understand the Kalix concepts that are the basis for this example, see Designing services in the documentation.
This project demonstrates the use of Event Sourced Entities, Subscriptions and Actions components. To understand more about these components, see Developing services and in particular the Java section
Use Maven to build your project:
mvn compile
When running a Kalix application locally, at least two applications are required. The current Kalix application and its companion Kalix Proxy.
To start the applications locally, call the following command:
mvn kalix:runAll
This command will start your Kalix application and a Kalix Proxy using the included [docker-compose.yml](. /docker-compose.yml) file.
By default, an orchestration
Spring profile is enabled, to demonstrate
orchestration-based Saga with the Workflow Entity. Switching to
choreography based Saga is just a matter of changing the profile configuration -Dspring.profiles.active
to
choreography
in pom.xml
file.
- Add product to the inventory
curl -XPATCH -H "Content-Type: application/json" \
--data '{"productId": "p1", "quantity": 50}' \
localhost:9000/inventory/global-inventory/add
- Place an order
curl -XPOST -H "Content-Type: application/json" \
--data '{"userId": "u1", "productId": "p1", "quantity": 10, "price": 10}' \
localhost:9000/order/123
- Check order status
curl localhost:9000/order/123
- Check remaining stocks
curl localhost:9000/inventory/global-inventory/product/p1
- Place an order with payments failure. Payment will fail for an order with an
id
set to42
.
curl -XPOST -H "Content-Type: application/json" \
--data '{"userId": "u1", "productId": "p1", "quantity": 10, "price": 10}' \
localhost:9000/order/42
- Check order status
curl localhost:9000/order/42
There are two integration tests: OrderWorkflowIntegrationTest
and OrderEntityIntegrationTest
to validate orchestration and choreography-based Sagas.