Skip to content

Commit

Permalink
order sada demo
Browse files Browse the repository at this point in the history
  • Loading branch information
aludwiko committed May 17, 2023
1 parent c6932bd commit bf5b4e2
Show file tree
Hide file tree
Showing 35 changed files with 1,359 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
.idea
86 changes: 85 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,85 @@
# kalix-order-saga
# Kalix Order Saga

## Designing

To understand the Kalix concepts that are the basis for this example, see [Designing services](https://docs.kalix.io/java/development-process.html) in the documentation.

## Developing

This project demonstrates the use of Event Sourced Entities, Subscriptions and Actions components.
To understand more about these components, see [Developing services](https://docs.kalix.io/services/)
and in particular the [Java section](https://docs.kalix.io/java/)

## Building

Use Maven to build your project:

```shell
mvn compile
```

## Running Locally

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:

```shell
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](https://docs.kalix.io/java/workflow-entities.html). Switching to
choreography based Saga is just a matter of changing the profile configuration `-Dspring.profiles.active` to
`choreography` in `pom.xml` file.

## Exercising the service

- Add product to the inventory

```shell
curl -XPATCH -H "Content-Type: application/json" \
--data '{"productId": "p1", "quantity": 50}' \
localhost:9000/inventory/global-inventory/add
```

- Place an order

```shell
curl -XPOST -H "Content-Type: application/json" \
--data '{"userId": "u1", "productId": "p1", "quantity": 10, "price": 10}' \
localhost:9000/order/123
```

- Check order status

```shell
curl localhost:9000/order/123
```

- Check remaining stocks

```shell
curl localhost:9000/inventory/global-inventory/product/p1
```

- Place an order with payments failure. Payment will fail for an order with an `id` set to `42`.

```shell
curl -XPOST -H "Content-Type: application/json" \
--data '{"userId": "u1", "productId": "p1", "quantity": 10, "price": 10}' \
localhost:9000/order/42
```

- Check order status

```shell
curl localhost:9000/order/42
```

## Testing

There are two integration tests: `OrderWorkflowIntegrationTest` and `OrderEntityIntegrationTest` to validate orchestration and choreography-based Sagas.
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# If you're looking to use eventing with Google PubSub, to get an emulator running:
# - add property "-Dkalix.proxy.eventing.support=google-pubsub-emulator" to the JAVA_TOOL_OPTIONS environment map under the kalix-proxy service
# - uncomment the env var PUBSUB_EMULATOR_HOST and the section below for gcloud-pubsub-emulator service
version: "3"
services:
kalix-proxy:
image: gcr.io/kalix-public/kalix-proxy:1.1.8
ports:
- "9000:9000"
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
JAVA_TOOL_OPTIONS: >
-Dconfig.resource=dev-mode.conf
-Dlogback.configurationFile=logback-dev-mode.xml
USER_FUNCTION_HOST: ${USER_FUNCTION_HOST:-host.docker.internal}
USER_FUNCTION_PORT: ${USER_FUNCTION_PORT:-8080}
# Comment to enable ACL check in dev-mode (see https://docs.kalix.io/services/using-acls.html#_local_development_with_acls)
ACL_ENABLED: "false"
#PUBSUB_EMULATOR_HOST: gcloud-pubsub-emulator
#gcloud-pubsub-emulator:
# image: gcr.io/google.com/cloudsdktool/cloud-sdk:341.0.0
# command: gcloud beta emulators pubsub start --project=test --host-port=0.0.0.0:8085
# ports:
# - 8085:8085
Loading

0 comments on commit bf5b4e2

Please sign in to comment.