diff --git a/.github/holopin.yml b/.github/holopin.yml new file mode 100644 index 000000000..44a7f0c8a --- /dev/null +++ b/.github/holopin.yml @@ -0,0 +1,6 @@ +organization: dapr +defaultSticker: clmjkxscc122740fl0mkmb7egi +stickers: + - + id: clmjkxscc122740fl0mkmb7egi + alias: ghc2023 diff --git a/.github/workflows/validate_python_quicstarts.yaml b/.github/workflows/validate_python_quicstarts.yaml index 58c021aa3..447d4f0cc 100644 --- a/.github/workflows/validate_python_quicstarts.yaml +++ b/.github/workflows/validate_python_quicstarts.yaml @@ -99,6 +99,7 @@ jobs: echo "PATH=$PATH:$HOME/.local/bin" >> $GITHUB_ENV pip3 install setuptools wheel pip3 install mechanical-markdown + pip3 install fastapi uvicorn - name: Validate building blocks with Python run: | variants=("http" "sdk") diff --git a/actors/csharp/sdk/client/SmartDevice.Client.csproj b/actors/csharp/sdk/client/SmartDevice.Client.csproj index a5c9a185c..98c293a64 100644 --- a/actors/csharp/sdk/client/SmartDevice.Client.csproj +++ b/actors/csharp/sdk/client/SmartDevice.Client.csproj @@ -8,7 +8,7 @@ - + diff --git a/actors/csharp/sdk/interfaces/SmartDevice.Interfaces.csproj b/actors/csharp/sdk/interfaces/SmartDevice.Interfaces.csproj index 1ab301045..71be0b00f 100644 --- a/actors/csharp/sdk/interfaces/SmartDevice.Interfaces.csproj +++ b/actors/csharp/sdk/interfaces/SmartDevice.Interfaces.csproj @@ -7,7 +7,7 @@ - + diff --git a/actors/csharp/sdk/service/SmartDevice.Service.csproj b/actors/csharp/sdk/service/SmartDevice.Service.csproj index 67372b4ab..bf0f90666 100644 --- a/actors/csharp/sdk/service/SmartDevice.Service.csproj +++ b/actors/csharp/sdk/service/SmartDevice.Service.csproj @@ -7,8 +7,8 @@ - - + + diff --git a/bindings/csharp/sdk/batch/batch.csproj b/bindings/csharp/sdk/batch/batch.csproj index 138c5edbe..19dd645d3 100644 --- a/bindings/csharp/sdk/batch/batch.csproj +++ b/bindings/csharp/sdk/batch/batch.csproj @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/configuration/csharp/sdk/order-processor/Program.csproj b/configuration/csharp/sdk/order-processor/Program.csproj index a2f2667b0..dd54cdbe4 100644 --- a/configuration/csharp/sdk/order-processor/Program.csproj +++ b/configuration/csharp/sdk/order-processor/Program.csproj @@ -6,7 +6,7 @@ - + diff --git a/pub_sub/csharp/http/README.md b/pub_sub/csharp/http/README.md index 32f59e953..155084255 100644 --- a/pub_sub/csharp/http/README.md +++ b/pub_sub/csharp/http/README.md @@ -14,78 +14,87 @@ And one subscriber: - Dotnet subscriber `order-processor` -### Run Dotnet message subscriber with Dapr +## Run all apps with multi-app run template file: -1. Navigate to the directory and install dependencies: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. - - -```bash -cd ./order-processor -dotnet restore -dotnet build -``` - -2. Run the Dotnet subscriber app with Dapr: +1. Open a new terminal window and run `order-processor` and `checkout` using the multi app run template defined in [dapr.yaml](./dapr.yaml): - ```bash -dapr run --app-id order-processor-http --resources-path ../../../components/ --app-port 7005 -- dotnet run --project . +dapr run -f . ``` +The terminal console output should look similar to this: + +```text +== APP - checkout-http == Published data: Order { OrderId = 1 } +== APP - order-processor-http == Subscriber received : 1 +== APP - checkout-http == Published data: Order { OrderId = 2 } +== APP - order-processor-http == Subscriber received : 2 +== APP - checkout-http == Published data: Order { OrderId = 3 } +== APP - order-processor-http == Subscriber received : 3 +== APP - checkout-http == Published data: Order { OrderId = 4 } +== APP - order-processor-http == Subscriber received : 4 +== APP - checkout-http == Published data: Order { OrderId = 5 } +== APP - order-processor-http == Subscriber received : 5 +== APP - checkout-http == Published data: Order { OrderId = 6 } +== APP - order-processor-http == Subscriber received : 6 +== APP - checkout-http == Published data: Order { OrderId = 7 } +== APP - order-processor-http == Subscriber received : 7 +== APP - checkout-http == Published data: Order { OrderId = 8 } +== APP - order-processor-http == Subscriber received : 8 +== APP - checkout-http == Published data: Order { OrderId = 9 } +== APP - order-processor-http == Subscriber received : 9 +== APP - checkout-http == Published data: Order { OrderId = 10 } +== APP - order-processor-http == Subscriber received : 10 +``` + +2. Stop and clean up application processes + +```bash +dapr stop -f . +``` -### Run Dotnet message publisher with Dapr -1. Navigate to the directory and install dependencies: +## Run a single app at a time with Dapr (Optional) - +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + +### Run Dotnet message subscriber with Dapr + +1. Run the Dotnet subscriber app with Dapr: ```bash -cd ./checkout -dotnet restore -dotnet build +cd ./order-processor +dapr run --app-id order-processor-http --resources-path ../../../components/ --app-port 7005 -- dotnet run ``` - -2. Run the Dotnet publisher app with Dapr: - - +### Run Dotnet message publisher with Dapr + +1. Run the Dotnet publisher app with Dapr: + + ```bash -dapr run --app-id checkout-http --resources-path ../../../components/ -- dotnet run --project . +cd ./checkout +dapr run --app-id checkout-http --resources-path ../../../components/ -- dotnet run ``` - +2. Stop and clean up application processes ```bash dapr stop --app-id order-processor-http diff --git a/pub_sub/csharp/http/dapr.yaml b/pub_sub/csharp/http/dapr.yaml new file mode 100644 index 000000000..25d7770ff --- /dev/null +++ b/pub_sub/csharp/http/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-http + appDirPath: ./order-processor/ + appPort: 7005 + command: ["dotnet", "run"] + - appID: checkout-http + appDirPath: ./checkout/ + command: ["dotnet", "run"] diff --git a/pub_sub/csharp/sdk/README.md b/pub_sub/csharp/sdk/README.md index 04f3010a2..199b72af3 100644 --- a/pub_sub/csharp/sdk/README.md +++ b/pub_sub/csharp/sdk/README.md @@ -14,78 +14,87 @@ And one subscriber: - Dotnet subscriber `order-processor` -### Run Dotnet message subscriber with Dapr +## Run all apps with multi-app run template file: -1. Navigate to the directory and install dependencies: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. - - -```bash -cd ./order-processor -dotnet restore -dotnet build -``` - -2. Run the Dotnet subscriber app with Dapr: +1. Open a new terminal window and run the multi app run template: - ```bash -dapr run --app-id order-processor --resources-path ../../../components/ --app-port 7006 -- dotnet run --project . +dapr run -f . ``` +The terminal console output should look similar to this: + +```text +== APP - checkout-sdk == Published data: Order { OrderId = 1 } +== APP - order-processor == Subscriber received : Order { OrderId = 1 } +== APP - checkout-sdk == Published data: Order { OrderId = 2 } +== APP - order-processor == Subscriber received : Order { OrderId = 2 } +== APP - checkout-sdk == Published data: Order { OrderId = 3 } +== APP - order-processor == Subscriber received : Order { OrderId = 3 } +== APP - checkout-sdk == Published data: Order { OrderId = 4 } +== APP - order-processor == Subscriber received : Order { OrderId = 4 } +== APP - checkout-sdk == Published data: Order { OrderId = 5 } +== APP - order-processor == Subscriber received : Order { OrderId = 5 } +== APP - checkout-sdk == Published data: Order { OrderId = 6 } +== APP - order-processor == Subscriber received : Order { OrderId = 6 } +== APP - checkout-sdk == Published data: Order { OrderId = 7 } +== APP - order-processor == Subscriber received : Order { OrderId = 7 } +== APP - checkout-sdk == Published data: Order { OrderId = 8 } +== APP - order-processor == Subscriber received : Order { OrderId = 8 } +== APP - checkout-sdk == Published data: Order { OrderId = 9 } +== APP - order-processor == Subscriber received : Order { OrderId = 9 } +== APP - checkout-sdk == Published data: Order { OrderId = 10 } +== APP - order-processor == Subscriber received : Order { OrderId = 10 } +``` + +2. Stop and clean up application processes + +```bash +dapr stop -f . +``` -### Run Dotnet message publisher with Dapr -1. Navigate to the directory and install dependencies: +## Run a single app at a time with Dapr (Optional) - +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + +### Run Dotnet message subscriber with Dapr + +1. Run the Dotnet subscriber app with Dapr: ```bash -cd ./checkout -dotnet restore -dotnet build +cd ./order-processor +dapr run --app-id order-processor --resources-path ../../../components/ --app-port 7006 -- dotnet run ``` - -2. Run the Dotnet publisher app with Dapr: - - +### Run Dotnet message publisher with Dapr + +1. Run the Dotnet publisher app with Dapr: + + ```bash -dapr run --app-id checkout-sdk --resources-path ../../../components/ -- dotnet run --project . +cd ./checkout +dapr run --app-id checkout-sdk --resources-path ../../../components/ -- dotnet run ``` - +2. Stop and clean up application processes ```bash dapr stop --app-id order-processor diff --git a/pub_sub/csharp/sdk/checkout/checkout.csproj b/pub_sub/csharp/sdk/checkout/checkout.csproj index 38b8650fe..dd54cdbe4 100644 --- a/pub_sub/csharp/sdk/checkout/checkout.csproj +++ b/pub_sub/csharp/sdk/checkout/checkout.csproj @@ -6,7 +6,7 @@ - + diff --git a/pub_sub/csharp/sdk/dapr.yaml b/pub_sub/csharp/sdk/dapr.yaml new file mode 100644 index 000000000..5d026f7a2 --- /dev/null +++ b/pub_sub/csharp/sdk/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + appPort: 7006 + command: ["dotnet", "run"] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["dotnet", "run"] diff --git a/pub_sub/csharp/sdk/order-processor/order-processor.csproj b/pub_sub/csharp/sdk/order-processor/order-processor.csproj index ad14db940..adbe897aa 100644 --- a/pub_sub/csharp/sdk/order-processor/order-processor.csproj +++ b/pub_sub/csharp/sdk/order-processor/order-processor.csproj @@ -9,7 +9,7 @@ - + diff --git a/pub_sub/go/http/README.md b/pub_sub/go/http/README.md index 8f8aeaab0..6a4ec529e 100644 --- a/pub_sub/go/http/README.md +++ b/pub_sub/go/http/README.md @@ -10,51 +10,85 @@ This quickstart includes one publisher: Go client message generator `checkout`. And one subscriber: Go subscriber `order-processor`. -### Run Go message subscriber with Dapr +## Run all apps with multi-app run template file: -1. Run the Go subscriber app with Dapr in the `order-processor` folder: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Open a new terminal window and run the multi app run template: ```bash -cd ./order-processor -dapr run --app-port 6002 --app-id order-processor --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run . +dapr run -f . ``` +The terminal console output should look similar to this: + +```text +== APP - checkout-http == Published data: {"orderId":1} +== APP - order-processor-http == Subscriber received: {"orderId":1} +== APP - checkout-http == Published data: {"orderId":2} +== APP - order-processor-http == Subscriber received: {"orderId":2} +== APP - checkout-http == Published data: {"orderId":3} +== APP - order-processor-http == Subscriber received: {"orderId":3} +== APP - checkout-http == Published data: {"orderId":4} +== APP - order-processor-http == Subscriber received: {"orderId":4} +== APP - checkout-http == Published data: {"orderId":5} +== APP - order-processor-http == Subscriber received: {"orderId":5} +== APP - checkout-http == Published data: {"orderId":6} +== APP - order-processor-http == Subscriber received: {"orderId":6} +== APP - checkout-http == Published data: {"orderId":7} +== APP - order-processor-http == Subscriber received: {"orderId":7} +== APP - checkout-http == Published data: {"orderId":8} +== APP - order-processor-http == Subscriber received: {"orderId":8} +== APP - checkout-http == Published data: {"orderId":9} +== APP - order-processor-http == Subscriber received: {"orderId":9} +== APP - checkout-http == Published data: {"orderId":10} +== APP - order-processor-http == Subscriber received: {"orderId":10} +``` + +2. Stop and clean up application processes + +```bash +dapr stop -f . +``` +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + +### Run Go message subscriber with Dapr + +1. Run the Go subscriber app with Dapr in the `order-processor` folder: + +```bash +cd ./order-processor +dapr run --app-port 6003 --app-id order-processor-http --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run . +``` + ### Run Go message publisher with Dapr 1. Run the Go publisher app with Dapr in the `checkout` folder: - - ```bash cd ./checkout dapr run --app-id checkout-http --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- go run . ``` - - To stop: ```bash diff --git a/pub_sub/go/http/dapr.yaml b/pub_sub/go/http/dapr.yaml new file mode 100644 index 000000000..e6b04c161 --- /dev/null +++ b/pub_sub/go/http/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-http + appDirPath: ./order-processor/ + appPort: 6003 + command: ["go", "run", "."] + - appID: checkout-http + appDirPath: ./checkout/ + command: ["go", "run", "."] diff --git a/pub_sub/go/sdk/README.md b/pub_sub/go/sdk/README.md index 5b4f22ef7..1ebfaf9ca 100644 --- a/pub_sub/go/sdk/README.md +++ b/pub_sub/go/sdk/README.md @@ -10,51 +10,86 @@ This quickstart includes one publisher: Go client message generator `checkout` And one subscriber: Go subscriber `order-processor` -### Run Go message subscriber with Dapr +## Run all apps with multi-app run template file: -1. Run the Go subscriber app with Dapr in the `order-processor` folder: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Open a new terminal window and run the multi app run template: ```bash -cd ./order-processor -dapr run --app-port 6005 --app-id order-processor-sdk --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run . +dapr run -f . +``` + +The terminal console output should look similar to this: + +```text +== APP - checkout-sdk == Published data: {"orderId":1} +== APP - order-processor == Subscriber received: map[orderId:1] +== APP - checkout-sdk == Published data: {"orderId":2} +== APP - order-processor == Subscriber received: map[orderId:2] +== APP - checkout-sdk == Published data: {"orderId":3} +== APP - order-processor == Subscriber received: map[orderId:3] +== APP - checkout-sdk == Published data: {"orderId":4} +== APP - order-processor == Subscriber received: map[orderId:4] +== APP - checkout-sdk == Published data: {"orderId":5} +== APP - order-processor == Subscriber received: map[orderId:5] +== APP - checkout-sdk == Published data: {"orderId":6} +== APP - order-processor == Subscriber received: map[orderId:6] +== APP - checkout-sdk == Published data: {"orderId":7} +== APP - order-processor == Subscriber received: map[orderId:7] +== APP - checkout-sdk == Published data: {"orderId":8} +== APP - order-processor == Subscriber received: map[orderId:8] +== APP - checkout-sdk == Published data: {"orderId":9} +== APP - order-processor == Subscriber received: map[orderId:9] +== APP - checkout-sdk == Published data: {"orderId":10} +== APP - order-processor == Subscriber received: map[orderId:10] ``` +2. Stop and clean up application processes + +```bash +dapr stop -f . +``` +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + +### Run Go message subscriber with Dapr + +1. Run the Go subscriber app with Dapr in the `order-processor` folder: + + +```bash +cd ./order-processor +dapr run --app-port 6005 --app-id order-processor-sdk --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run . +``` + ### Run Go message publisher with Dapr 1 Run the Go publisher app with Dapr in the `checkout` folder: - - ```bash cd ./checkout dapr run --app-id checkout-sdk --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- go run . ``` - - To stop: ```bash diff --git a/pub_sub/go/sdk/dapr.yaml b/pub_sub/go/sdk/dapr.yaml new file mode 100644 index 000000000..2290474b3 --- /dev/null +++ b/pub_sub/go/sdk/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + appPort: 6005 + command: ["go", "run", "."] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["go", "run", "."] diff --git a/pub_sub/java/http/README.md b/pub_sub/java/http/README.md index 8d0a8673f..92b8e538c 100644 --- a/pub_sub/java/http/README.md +++ b/pub_sub/java/http/README.md @@ -23,69 +23,113 @@ And one subscriber: * [OpenJDK 11](https://jdk.java.net/11/) * [Apache Maven](https://maven.apache.org/install.html) version 3.x. -### Run Java message subscriber app with Dapr +## Run all apps with multi-app run template file: + +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Install dependencies: -1. Navigate to directory and install dependencies: - ```bash cd ./order-processor mvn clean install +cd .. +cd ./checkout +mvn clean install +cd .. ``` -2. Run the Java subscriber app with Dapr: +2. Open a new terminal window and run the multi app run template: + + +```bash +dapr run -f . +``` + +The terminal console output should look similar to this: + +```text +== APP - order-processor-http == 2023-09-04 14:25:37.624 INFO 88784 --- [nio-8080-exec-1] c.s.c.OrderProcessingServiceController : Subscriber received: 1 +== APP - checkout-http == 1175 [main] INFO com.service.CheckoutServiceApplication - Published data: 2 +== APP - order-processor-http == 2023-09-04 14:25:38.558 INFO 88784 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 2 +== APP - checkout-http == 2184 [main] INFO com.service.CheckoutServiceApplication - Published data: 3 +== APP - order-processor-http == 2023-09-04 14:25:39.567 INFO 88784 --- [nio-8080-exec-3] c.s.c.OrderProcessingServiceController : Subscriber received: 3 +== APP - checkout-http == 3195 [main] INFO com.service.CheckoutServiceApplication - Published data: 4 +== APP - order-processor-http == 2023-09-04 14:25:40.578 INFO 88784 --- [nio-8080-exec-4] c.s.c.OrderProcessingServiceController : Subscriber received: 4 +== APP - checkout-http == 4203 [main] INFO com.service.CheckoutServiceApplication - Published data: 5 +== APP - order-processor-http == 2023-09-04 14:25:41.586 INFO 88784 --- [nio-8080-exec-5] c.s.c.OrderProcessingServiceController : Subscriber received: 5 +== APP - checkout-http == 5215 [main] INFO com.service.CheckoutServiceApplication - Published data: 6 +== APP - order-processor-http == 2023-09-04 14:25:42.600 INFO 88784 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 6 +== APP - checkout-http == 6219 [main] INFO com.service.CheckoutServiceApplication - Published data: 7 +== APP - order-processor-http == 2023-09-04 14:25:43.601 INFO 88784 --- [nio-8080-exec-7] c.s.c.OrderProcessingServiceController : Subscriber received: 7 +== APP - checkout-http == 7224 [main] INFO com.service.CheckoutServiceApplication - Published data: 8 +== APP - order-processor-http == 2023-09-04 14:25:44.607 INFO 88784 --- [nio-8080-exec-8] c.s.c.OrderProcessingServiceController : Subscriber received: 8 +== APP - checkout-http == 8229 [main] INFO com.service.CheckoutServiceApplication - Published data: 9 +== APP - order-processor-http == 2023-09-04 14:25:45.612 INFO 88784 --- [nio-8080-exec-9] c.s.c.OrderProcessingServiceController : Subscriber received: 9 +== APP - checkout-http == 9237 [main] INFO com.service.CheckoutServiceApplication - Published data: 10 +== APP - order-processor-http == 2023-09-04 14:25:46.620 INFO 88784 --- [io-8080-exec-10] c.s.c.OrderProcessingServiceController : Subscriber received: 10 +``` + +3. Stop and clean up application processes + +```bash +dapr stop -f . +``` + + +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + + +### Run Java message subscriber app with Dapr + +1. Navigate to directory and install dependencies: + +```bash +cd ./order-processor +mvn clean install +``` + +2. Run the Java subscriber app with Dapr: + ```bash cd ./order-processor dapr run --app-port 8080 --app-id order-processor-http --resources-path ../../../components -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar ``` - + ### Run Java message publisher app with Dapr 1. Navigate to the directory and install dependencies: - - ```bash cd ./checkout mvn clean install ``` - 2. Run the Java publisher app with Dapr: - ```bash cd ./checkout dapr run --app-id checkout-http --resources-path ../../../components -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar ``` - ```bash dapr stop --app-id checkout-http diff --git a/pub_sub/java/http/checkout/src/main/java/com/service/CheckoutServiceApplication.java b/pub_sub/java/http/checkout/src/main/java/com/service/CheckoutServiceApplication.java index 73008cad7..277928297 100644 --- a/pub_sub/java/http/checkout/src/main/java/com/service/CheckoutServiceApplication.java +++ b/pub_sub/java/http/checkout/src/main/java/com/service/CheckoutServiceApplication.java @@ -26,7 +26,7 @@ public class CheckoutServiceApplication { public static void main(String[] args) throws InterruptedException, IOException { String uri = DAPR_HOST + ":" + DAPR_HTTP_PORT + "/v1.0/publish/" + PUBSUB_NAME + "/" + TOPIC; - for (int i = 0; i <= 10; i++) { + for (int i = 1; i <= 10; i++) { int orderId = i; JSONObject obj = new JSONObject(); obj.put("orderId", orderId); @@ -40,7 +40,7 @@ public static void main(String[] args) throws InterruptedException, IOException HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); logger.info("Published data: {}", orderId); - TimeUnit.MILLISECONDS.sleep(3000); + TimeUnit.MILLISECONDS.sleep(1000); } } } diff --git a/pub_sub/java/http/dapr.yaml b/pub_sub/java/http/dapr.yaml new file mode 100644 index 000000000..dfcf0a889 --- /dev/null +++ b/pub_sub/java/http/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-http + appDirPath: ./order-processor/target/ + appPort: 8080 + command: ["java", "-jar", "OrderProcessingService-0.0.1-SNAPSHOT.jar"] + - appID: checkout-http + appDirPath: ./checkout/target/ + command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"] diff --git a/pub_sub/java/sdk/README.md b/pub_sub/java/sdk/README.md index e71852c63..eda0264e1 100644 --- a/pub_sub/java/sdk/README.md +++ b/pub_sub/java/sdk/README.md @@ -23,70 +23,113 @@ And one subscriber: * [OpenJDK 11](https://jdk.java.net/11/) * [Apache Maven](https://maven.apache.org/install.html) version 3.x. -### Run Java message subscriber app with Dapr +## Run all apps with multi-app run template file: + +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Install dependencies: -1. Navigate to directory and install dependencies: - ```bash cd ./order-processor mvn clean install +cd .. +cd ./checkout +mvn clean install +cd .. ``` -2. Run the Java subscriber app with Dapr: +2. Open a new terminal window and run the multi app run template: + + +```bash +dapr run -f . +``` + +The terminal console output should look similar to this: + +```text +== APP - checkout-sdk == 563 [main] INFO com.service.CheckoutServiceApplication - Published data: 1 +== APP - order-processor-sdk == 2023-09-04 13:57:18.434 INFO 82828 --- [nio-8080-exec-3] c.s.c.OrderProcessingServiceController : Subscriber received: 1 +== APP - checkout-sdk == 1576 [main] INFO com.service.CheckoutServiceApplication - Published data: 2 +== APP - order-processor-sdk == 2023-09-04 13:57:19.419 INFO 82828 --- [nio-8080-exec-4] c.s.c.OrderProcessingServiceController : Subscriber received: 2 +== APP - checkout-sdk == 2587 [main] INFO com.service.CheckoutServiceApplication - Published data: 3 +== APP - order-processor-sdk == 2023-09-04 13:57:20.431 INFO 82828 --- [nio-8080-exec-5] c.s.c.OrderProcessingServiceController : Subscriber received: 3 +== APP - checkout-sdk == 3602 [main] INFO com.service.CheckoutServiceApplication - Published data: 4 +== APP - order-processor-sdk == 2023-09-04 13:57:21.447 INFO 82828 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 4 +== APP - checkout-sdk == 4612 [main] INFO com.service.CheckoutServiceApplication - Published data: 5 +== APP - order-processor-sdk == 2023-09-04 13:57:22.455 INFO 82828 --- [nio-8080-exec-7] c.s.c.OrderProcessingServiceController : Subscriber received: 5 +== APP - checkout-sdk == 5624 [main] INFO com.service.CheckoutServiceApplication - Published data: 6 +== APP - order-processor-sdk == 2023-09-04 13:57:23.468 INFO 82828 --- [nio-8080-exec-8] c.s.c.OrderProcessingServiceController : Subscriber received: 6 +== APP - checkout-sdk == 6631 [main] INFO com.service.CheckoutServiceApplication - Published data: 7 +== APP - order-processor-sdk == 2023-09-04 13:57:24.474 INFO 82828 --- [nio-8080-exec-9] c.s.c.OrderProcessingServiceController : Subscriber received: 7 +== APP - checkout-sdk == 7643 [main] INFO com.service.CheckoutServiceApplication - Published data: 8 +== APP - order-processor-sdk == 2023-09-04 13:57:25.487 INFO 82828 --- [io-8080-exec-10] c.s.c.OrderProcessingServiceController : Subscriber received: 8 +== APP - checkout-sdk == 8649 [main] INFO com.service.CheckoutServiceApplication - Published data: 9 +== APP - order-processor-sdk == 2023-09-04 13:57:26.492 INFO 82828 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 9 +== APP - checkout-sdk == 9662 [main] INFO com.service.CheckoutServiceApplication - Published data: 10 +== APP - order-processor-sdk == 2023-09-04 13:57:27.504 INFO 82828 --- [nio-8080-exec-1] c.s.c.OrderProcessingServiceController : Subscriber received: 10 +``` + +3. Stop and clean up application processes + +```bash +dapr stop -f . +``` + + +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + +### Run Java message subscriber app with Dapr + +1. Navigate to directory and install dependencies: + +```bash +cd ./order-processor +mvn clean install +``` + +2. Run the Java subscriber app with Dapr: + ```bash cd ./order-processor dapr run --app-port 8080 --app-id order-processor-sdk --resources-path ../../../components -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar ``` - ### Run Java message publisher app with Dapr 1. Navigate to the directory and install dependencies: - - ```bash cd ./checkout mvn clean install ``` - 2. Run the Java publisher app with Dapr: - ```bash cd ./checkout dapr run --app-id checkout-sdk --resources-path ../../../components -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar ``` - ```bash dapr stop --app-id checkout-sdk diff --git a/pub_sub/java/sdk/checkout/src/main/java/com/service/CheckoutServiceApplication.java b/pub_sub/java/sdk/checkout/src/main/java/com/service/CheckoutServiceApplication.java index db8dfab2d..66eead410 100644 --- a/pub_sub/java/sdk/checkout/src/main/java/com/service/CheckoutServiceApplication.java +++ b/pub_sub/java/sdk/checkout/src/main/java/com/service/CheckoutServiceApplication.java @@ -16,7 +16,7 @@ public static void main(String[] args) throws InterruptedException{ String PUBSUB_NAME = "orderpubsub"; DaprClient client = new DaprClientBuilder().build(); - for (int i = 0; i <= 10; i++) { + for (int i = 1; i <= 10; i++) { int orderId = i; Order order = new Order(orderId); @@ -26,7 +26,7 @@ public static void main(String[] args) throws InterruptedException{ TOPIC_NAME, order).block(); logger.info("Published data: " + order.getOrderId()); - TimeUnit.MILLISECONDS.sleep(5000); + TimeUnit.MILLISECONDS.sleep(1000); } } } diff --git a/pub_sub/java/sdk/dapr.yaml b/pub_sub/java/sdk/dapr.yaml new file mode 100644 index 000000000..f9407f562 --- /dev/null +++ b/pub_sub/java/sdk/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-sdk + appDirPath: ./order-processor/target/ + appPort: 8080 + command: ["java", "-jar", "OrderProcessingService-0.0.1-SNAPSHOT.jar"] + - appID: checkout-sdk + appDirPath: ./checkout/target/ + command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"] diff --git a/pub_sub/javascript/http/README.md b/pub_sub/javascript/http/README.md index 5ce0d9b79..701de48be 100644 --- a/pub_sub/javascript/http/README.md +++ b/pub_sub/javascript/http/README.md @@ -14,7 +14,9 @@ And one subscriber: - Node subscriber `order-processor` -### Run Node message subscriber with Dapr +## Run all apps with multi-app run template file: + +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. 1. Install dependencies: @@ -25,61 +27,101 @@ name: Install Node dependencies ```bash cd ./order-processor npm install +cd .. +cd ./checkout +npm install +cd .. ``` -2. Run the Node publisher app with Dapr: + +2. Open a new terminal window and run the multi app run template: - + ```bash -dapr run --app-id order-processor-http --resources-path ../../../components/ --app-port 5003 -- node . +dapr run -f . ``` +The terminal console output should look similar to this: + +```text +== APP - checkout-sdk-http == Published data: {"orderId":1} +== APP - order-processor-http == Subscriber received: { orderId: 1 } +== APP - checkout-sdk-http == Published data: {"orderId":2} +== APP - order-processor-http == Subscriber received: { orderId: 2 } +== APP - checkout-sdk-http == Published data: {"orderId":3} +== APP - order-processor-http == Subscriber received: { orderId: 3 } +== APP - checkout-sdk-http == Published data: {"orderId":4} +== APP - order-processor-http == Subscriber received: { orderId: 4 } +== APP - checkout-sdk-http == Published data: {"orderId":5} +== APP - order-processor-http == Subscriber received: { orderId: 5 } +== APP - checkout-sdk-http == Published data: {"orderId":6} +== APP - order-processor-http == Subscriber received: { orderId: 6 } +== APP - checkout-sdk-http == Published data: {"orderId":7} +== APP - order-processor-http == Subscriber received: { orderId: 7 } +== APP - checkout-sdk-http == Published data: {"orderId":8} +== APP - order-processor-http == Subscriber received: { orderId: 8 } +== APP - checkout-sdk-http == Published data: {"orderId":9} +== APP - order-processor-http == Subscriber received: { orderId: 9 } +== APP - checkout-sdk-http == Published data: {"orderId":10} +== APP - order-processor-http == Subscriber received: { orderId: 10 } +``` + +3. Stop and clean up application processes + +```bash +dapr stop -f . +``` -### Run Node message publisher with Dapr +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- npm run start` commands. This next section covers how to do this. + +### Run Node message subscriber with Dapr 1. Install dependencies: - +```bash +cd ./order-processor +npm install +``` + +2. Run the Node publisher app with Dapr: + +```bash +dapr run --app-port 5003 --app-id order-processing-http --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- npm run start +``` + +### Run Node message publisher with Dapr + +1. Install dependencies: ```bash cd ./checkout npm install ``` - -2. Run the Node publisher app with Dapr: - +2. Run the Node publisher app with Dapr: ```bash -dapr run --app-id checkout-http --resources-path ../../../components/ --app-port 5003 -- node . +dapr run --app-id checkout-http --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- npm run start ``` - +### Stop the apps and clean up ```bash dapr stop --app-id checkout-http diff --git a/pub_sub/javascript/http/checkout/package-lock.json b/pub_sub/javascript/http/checkout/package-lock.json index 35b2a221b..8fa6abdb2 100644 --- a/pub_sub/javascript/http/checkout/package-lock.json +++ b/pub_sub/javascript/http/checkout/package-lock.json @@ -1,21 +1,43 @@ { "name": "checkout", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 3, "requires": true, - "dependencies": { - "axios": { + "packages": { + "": { + "name": "checkout", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "axios": "^0.25.0" + } + }, + "node_modules/axios": { "version": "0.25.0", "resolved": "https://registry.npmjs.org/axios/-/axios-0.25.0.tgz", "integrity": "sha512-cD8FOb0tRH3uuEe6+evtAbgJtfxr7ly3fQjYcMcuPlgkwVS9xboaVIpcDV+cYQe+yGykgwZCs1pzjntcGa6l5g==", - "requires": { + "dependencies": { "follow-redirects": "^1.14.7" } }, - "follow-redirects": { + "node_modules/follow-redirects": { "version": "1.14.7", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz", - "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==" + "integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } } } } diff --git a/pub_sub/javascript/http/dapr.yaml b/pub_sub/javascript/http/dapr.yaml new file mode 100644 index 000000000..ecf3e17c9 --- /dev/null +++ b/pub_sub/javascript/http/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-http + appDirPath: ./order-processor/ + appPort: 5003 + command: ["npm", "run", "start"] + - appID: checkout-http + appDirPath: ./checkout/ + command: ["npm", "run", "start"] diff --git a/pub_sub/javascript/http/order-processor/package-lock.json b/pub_sub/javascript/http/order-processor/package-lock.json index 30535e45e..e1f057184 100644 --- a/pub_sub/javascript/http/order-processor/package-lock.json +++ b/pub_sub/javascript/http/order-processor/package-lock.json @@ -1,28 +1,39 @@ { "name": "order-processor", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 3, "requires": true, - "dependencies": { - "accepts": { + "packages": { + "": { + "name": "order-processor", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "express": "^4.17.2" + } + }, + "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", - "requires": { + "dependencies": { "mime-types": "~2.1.34", "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" } }, - "array-flatten": { + "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, - "body-parser": { + "node_modules/body-parser": { "version": "1.19.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.1.tgz", "integrity": "sha512-8ljfQi5eBk8EJfECMrgqNGWPEY5jWP+1IzkzkGdFFEwFQZZyaZ21UqdaHktgiMlH0xLHqIFtE/u2OYE5dOtViA==", - "requires": { + "dependencies": { "bytes": "3.1.1", "content-type": "~1.0.4", "debug": "2.6.9", @@ -33,79 +44,103 @@ "qs": "6.9.6", "raw-body": "2.4.2", "type-is": "~1.6.18" + }, + "engines": { + "node": ">= 0.8" } }, - "bytes": { + "node_modules/bytes": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.1.tgz", - "integrity": "sha512-dWe4nWO/ruEOY7HkUJ5gFt1DCFV9zPRoJr8pV0/ASQermOZjtq8jMjOprC0Kd10GLN+l7xaUPvxzJFWtxGu8Fg==" + "integrity": "sha512-dWe4nWO/ruEOY7HkUJ5gFt1DCFV9zPRoJr8pV0/ASQermOZjtq8jMjOprC0Kd10GLN+l7xaUPvxzJFWtxGu8Fg==", + "engines": { + "node": ">= 0.8" + } }, - "content-disposition": { + "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", - "requires": { + "dependencies": { "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" } }, - "content-type": { + "node_modules/content-type": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", + "engines": { + "node": ">= 0.6" + } }, - "cookie": { + "node_modules/cookie": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", - "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==" + "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==", + "engines": { + "node": ">= 0.6" + } }, - "cookie-signature": { + "node_modules/cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, - "debug": { + "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "requires": { + "dependencies": { "ms": "2.0.0" } }, - "depd": { + "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "engines": { + "node": ">= 0.6" + } }, - "destroy": { + "node_modules/destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, - "ee-first": { + "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, - "encodeurl": { + "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "engines": { + "node": ">= 0.8" + } }, - "escape-html": { + "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" }, - "etag": { + "node_modules/etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", + "engines": { + "node": ">= 0.6" + } }, - "express": { + "node_modules/express": { "version": "4.17.2", "resolved": "https://registry.npmjs.org/express/-/express-4.17.2.tgz", "integrity": "sha512-oxlxJxcQlYwqPWKVJJtvQiwHgosH/LrLSPA+H4UxpyvSS6jC5aH+5MoHFM+KABgTOt0APue4w66Ha8jCUo9QGg==", - "requires": { + "dependencies": { "accepts": "~1.3.7", "array-flatten": "1.1.1", "body-parser": "1.19.1", @@ -136,13 +171,16 @@ "type-is": "~1.6.18", "utils-merge": "1.0.1", "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" } }, - "finalhandler": { + "node_modules/finalhandler": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", - "requires": { + "dependencies": { "debug": "2.6.9", "encodeurl": "~1.0.2", "escape-html": "~1.0.3", @@ -150,154 +188,228 @@ "parseurl": "~1.3.3", "statuses": "~1.5.0", "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" } }, - "forwarded": { + "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", - "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==" + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "engines": { + "node": ">= 0.6" + } }, - "fresh": { + "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", + "engines": { + "node": ">= 0.6" + } }, - "http-errors": { + "node_modules/http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", - "requires": { + "dependencies": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.6" } }, - "iconv-lite": { + "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", - "requires": { + "dependencies": { "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" } }, - "inherits": { + "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, - "ipaddr.js": { + "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "engines": { + "node": ">= 0.10" + } }, - "media-typer": { + "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", + "engines": { + "node": ">= 0.6" + } }, - "merge-descriptors": { + "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" }, - "methods": { + "node_modules/methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", + "engines": { + "node": ">= 0.6" + } }, - "mime": { + "node_modules/mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", - "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==" + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } }, - "mime-db": { + "node_modules/mime-db": { "version": "1.51.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz", - "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==" + "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==", + "engines": { + "node": ">= 0.6" + } }, - "mime-types": { + "node_modules/mime-types": { "version": "2.1.34", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==", - "requires": { + "dependencies": { "mime-db": "1.51.0" + }, + "engines": { + "node": ">= 0.6" } }, - "ms": { + "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, - "negotiator": { + "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", - "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "engines": { + "node": ">= 0.6" + } }, - "on-finished": { + "node_modules/on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", - "requires": { + "dependencies": { "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" } }, - "parseurl": { + "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } }, - "path-to-regexp": { + "node_modules/path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, - "proxy-addr": { + "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", - "requires": { + "dependencies": { "forwarded": "0.2.0", "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" } }, - "qs": { + "node_modules/qs": { "version": "6.9.6", "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz", - "integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ==" + "integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ==", + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, - "range-parser": { + "node_modules/range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } }, - "raw-body": { + "node_modules/raw-body": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.2.tgz", "integrity": "sha512-RPMAFUJP19WIet/99ngh6Iv8fzAbqum4Li7AD6DtGaW2RpMB/11xDoalPiJMTbu6I3hkbMVkATvZrqb9EEqeeQ==", - "requires": { + "dependencies": { "bytes": "3.1.1", "http-errors": "1.8.1", "iconv-lite": "0.4.24", "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8" } }, - "safe-buffer": { + "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] }, - "safer-buffer": { + "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "send": { + "node_modules/send": { "version": "0.17.2", "resolved": "https://registry.npmjs.org/send/-/send-0.17.2.tgz", "integrity": "sha512-UJYB6wFSJE3G00nEivR5rgWp8c2xXvJ3OPWPhmuteU0IKj8nKbG3DrjiOmLwpnHGYWAVwA69zmTm++YG0Hmwww==", - "requires": { + "dependencies": { "debug": "2.6.9", "depd": "~1.1.2", "destroy": "~1.0.4", @@ -312,63 +424,85 @@ "range-parser": "~1.2.1", "statuses": "~1.5.0" }, - "dependencies": { - "ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" - } + "engines": { + "node": ">= 0.8.0" } }, - "serve-static": { + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/serve-static": { "version": "1.14.2", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.2.tgz", "integrity": "sha512-+TMNA9AFxUEGuC0z2mevogSnn9MXKb4fa7ngeRMJaaGv8vTwnIEkKi+QGvPt33HSnf8pRS+WGM0EbMtCJLKMBQ==", - "requires": { + "dependencies": { "encodeurl": "~1.0.2", "escape-html": "~1.0.3", "parseurl": "~1.3.3", "send": "0.17.2" + }, + "engines": { + "node": ">= 0.8.0" } }, - "setprototypeof": { + "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, - "statuses": { + "node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", + "engines": { + "node": ">= 0.6" + } }, - "toidentifier": { + "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", - "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } }, - "type-is": { + "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", - "requires": { + "dependencies": { "media-typer": "0.3.0", "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" } }, - "unpipe": { + "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", + "engines": { + "node": ">= 0.8" + } }, - "utils-merge": { + "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", + "engines": { + "node": ">= 0.4.0" + } }, - "vary": { + "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=", + "engines": { + "node": ">= 0.8" + } } } } diff --git a/pub_sub/javascript/sdk/README.md b/pub_sub/javascript/sdk/README.md index a81e157b3..91dfd1a8d 100644 --- a/pub_sub/javascript/sdk/README.md +++ b/pub_sub/javascript/sdk/README.md @@ -14,7 +14,9 @@ And one subscriber: - Node subscriber `order-processor` -### Run Node message subscriber with Dapr +## Run all apps with multi-app run template file: + +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. 1. Install dependencies: @@ -25,61 +27,101 @@ name: Install Node dependencies ```bash cd ./order-processor npm install +cd .. +cd ./checkout +npm install +cd .. ``` -3. Run the Node publisher app with Dapr: + +2. Open a new terminal window and run the multi app run template: - + ```bash -dapr run --app-port 5002 --app-id order-processing-sdk --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- npm run start +dapr run -f . ``` +The terminal console output should look similar to this: + +```text +== APP - checkout-sdk == Published data: {"orderId":1} +== APP - order-processor == Subscriber received: {"orderId":1} +== APP - checkout-sdk == Published data: {"orderId":2} +== APP - order-processor == Subscriber received: {"orderId":2} +== APP - checkout-sdk == Published data: {"orderId":3} +== APP - order-processor == Subscriber received: {"orderId":3} +== APP - checkout-sdk == Published data: {"orderId":4} +== APP - order-processor == Subscriber received: {"orderId":4} +== APP - checkout-sdk == Published data: {"orderId":5} +== APP - order-processor == Subscriber received: {"orderId":5} +== APP - checkout-sdk == Published data: {"orderId":6} +== APP - order-processor == Subscriber received: {"orderId":6} +== APP - checkout-sdk == Published data: {"orderId":7} +== APP - order-processor == Subscriber received: {"orderId":7} +== APP - checkout-sdk == Published data: {"orderId":8} +== APP - order-processor == Subscriber received: {"orderId":8} +== APP - checkout-sdk == Published data: {"orderId":9} +== APP - order-processor == Subscriber received: {"orderId":9} +== APP - checkout-sdk == Published data: {"orderId":10} +== APP - order-processor == Subscriber received: {"orderId":10} +``` + +3. Stop and clean up application processes + +```bash +dapr stop -f . +``` -### Run Node message publisher with Dapr +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. + +### Run Node message subscriber with Dapr 1. Install dependencies: - +```bash +cd ./order-processor +npm install +``` + +2. Run the Node publisher app with Dapr: + +```bash +dapr run --app-port 5002 --app-id order-processing-sdk --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- npm run start +``` + +### Run Node message publisher with Dapr + +1. Install dependencies: ```bash cd ./checkout npm install ``` - -3. Run the Node publisher app with Dapr: - - +2. Run the Node publisher app with Dapr: + ```bash dapr run --app-id checkout-sdk --app-protocol http --dapr-http-port 3500 --resources-path ../../../components -- npm run start ``` - +### Stop the apps and clean up ```bash dapr stop --app-id checkout-sdk diff --git a/pub_sub/javascript/sdk/dapr.yaml b/pub_sub/javascript/sdk/dapr.yaml new file mode 100644 index 000000000..679ef5e8d --- /dev/null +++ b/pub_sub/javascript/sdk/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + appPort: 5002 + command: ["npm", "run", "start"] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["npm", "run", "start"] diff --git a/pub_sub/python/http/README.md b/pub_sub/python/http/README.md index ced8600e5..0bd25647b 100644 --- a/pub_sub/python/http/README.md +++ b/pub_sub/python/http/README.md @@ -14,73 +14,119 @@ And one subscriber: - Python subscriber `order-processor` -### Run Python message subscriber with Dapr +## Run all apps with multi-app run template file: + +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. -2. Install dependencies: +1. Install dependencies: ```bash +cd ./checkout +pip3 install -r requirements.txt +cd .. cd ./order-processor -pip3 install -r requirements.txt +pip3 install -r requirements.txt +cd .. ``` -3. Run the Python subscriber app with Dapr: +2. Open a new terminal window and run the multi app run template: - ```bash -dapr run --app-id order-processor-http --resources-path ../../../components/ --app-port 6001 -- python3 app.py +dapr run -f . +``` + +The terminal console output should look similar to this: + +```text +== APP - order-processor-http == Subscriber received : 1 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:21] "POST /orders HTTP/1.1" 200 - +== APP - checkout-http == INFO:root:Published data: {"orderId": 2} +== APP - order-processor-http == Subscriber received : 2 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:22] "POST /orders HTTP/1.1" 200 - +== APP - checkout-http == INFO:root:Published data: {"orderId": 3} +== APP - order-processor-http == Subscriber received : 3 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:23] "POST /orders HTTP/1.1" 200 - +== APP - checkout-http == INFO:root:Published data: {"orderId": 4} +== APP - order-processor-http == Subscriber received : 4 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:24] "POST /orders HTTP/1.1" 200 - +== APP - checkout-http == INFO:root:Published data: {"orderId": 5} +== APP - order-processor-http == Subscriber received : 5 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:25] "POST /orders HTTP/1.1" 200 - +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:26] "POST /orders HTTP/1.1" 200 - +== APP - order-processor-http == Subscriber received : 6 +== APP - checkout-http == INFO:root:Published data: {"orderId": 6} +== APP - checkout-http == INFO:root:Published data: {"orderId": 7} +== APP - order-processor-http == Subscriber received : 7 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:27] "POST /orders HTTP/1.1" 200 - +== APP - checkout-http == INFO:root:Published data: {"orderId": 8} +== APP - order-processor-http == Subscriber received : 8 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:28] "POST /orders HTTP/1.1" 200 - +== APP - checkout-http == INFO:root:Published data: {"orderId": 9} +== APP - order-processor-http == Subscriber received : 9 +== APP - order-processor-http == 127.0.0.1 - - [04/Sep/2023 11:33:29] "POST /orders HTTP/1.1" 200 - ``` +3. Stop and clean up application processes + +```bash +dapr stop -f . +``` -### Run Python message publisher with Dapr +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- python3 app.py` commands. This next section covers how to do this. + +### Run Python message subscriber with Dapr 1. Install dependencies: - +```bash +cd ./order-processor +pip3 install -r requirements.txt +``` + +2. Run the Python subscriber app with Dapr: + +```bash +dapr run --app-id order-processor-http --resources-path ../../../components/ --app-port 6021 -- uvicorn app:app --port 6002 +``` + +### Run Python message publisher with Dapr + +1. Install dependencies: ```bash cd ./checkout pip3 install -r requirements.txt ``` - -3. Run the Python publisher app with Dapr: - - +2. Run the Python publisher app with Dapr: + ```bash dapr run --app-id checkout-http --resources-path ../../../components/ -- python3 app.py ``` - +### Stop the apps and clean up ```bash dapr stop --app-id checkout-http diff --git a/pub_sub/python/http/dapr.yaml b/pub_sub/python/http/dapr.yaml new file mode 100644 index 000000000..c1d9d1763 --- /dev/null +++ b/pub_sub/python/http/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-http + appDirPath: ./order-processor/ + appPort: 6021 + command: ["uvicorn", "app:app"] + - appID: checkout-http + appDirPath: ./checkout/ + command: ["python3", "app.py"] diff --git a/pub_sub/python/sdk/README.md b/pub_sub/python/sdk/README.md index 17120e067..db98ab869 100644 --- a/pub_sub/python/sdk/README.md +++ b/pub_sub/python/sdk/README.md @@ -14,104 +14,128 @@ And one subscriber: - Python subscriber `order-processor` -### Run Python message subscriber with Dapr +## Run all apps with multi-app run template file: + +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Install dependencies: 1. Run the Python subscriber app (flask version) with Dapr: ```bash +cd ./checkout +pip3 install -r requirements.txt +cd .. cd ./order-processor pip3 install -r requirements.txt +cd .. +cd ./order-processor-fastapi +pip3 install -r requirements.txt +cd .. ``` - +2. Open a new terminal window and run the multi app run template: + + ```bash -dapr run --app-id order-processor-sdk --resources-path ../../../components/ --app-port 6002 -- uvicorn app:app --port 6002 +dapr run -f . ``` - +The terminal console output should look similar to this: + +```text +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 1} +== APP - order-processor-sdk == Subscriber received : 1 +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:19] "POST /orders HTTP/1.1" 200 - +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 2} +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:20] "POST /orders HTTP/1.1" 200 - +== APP - order-processor-sdk == Subscriber received : 2 +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 3} +== APP - order-processor-sdk == Subscriber received : 3 +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:21] "POST /orders HTTP/1.1" 200 - +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 4} +== APP - order-processor-sdk == Subscriber received : 4 +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:22] "POST /orders HTTP/1.1" 200 - +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 5} +== APP - order-processor-sdk == Subscriber received : 5 +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:23] "POST /orders HTTP/1.1" 200 - +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 6} +== APP - order-processor-sdk == Subscriber received : 6 +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:24] "POST /orders HTTP/1.1" 200 - +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 7} +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:25] "POST /orders HTTP/1.1" 200 - +== APP - order-processor-sdk == Subscriber received : 7 +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 8} +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:26] "POST /orders HTTP/1.1" 200 - +== APP - order-processor-sdk == Subscriber received : 8 +== APP - checkout-sdk == INFO:root:Published data: {"orderId": 9} +== APP - order-processor-sdk == 127.0.0.1 - - [04/Sep/2023 11:15:27] "POST /orders HTTP/1.1" 200 - +== APP - order-processor-sdk == Subscriber received : 9 -2. Run the Python subscriber app (fastapi version) with Dapr: +``` - +3. Stop and clean up application processes ```bash -cd ./order-processor-fastapi -pip3 install -r requirements.txt +dapr stop -f . ``` - - +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- python3 app.py` commands. This next section covers how to do this. + +### Run Python message subscriber with Dapr + +1. Install dependencies: ```bash -dapr run --app-id order-processor-sdk-fastapi --resources-path ../../../components/ --app-port 6003 -- uvicorn app:app --port 6003 +cd ./order-processor +pip3 install -r requirements.txt ``` - +2. Run the Python subscriber app with Dapr: + +```bash +dapr run --app-id order-processor-sdk --resources-path ../../../components/ --app-port 6001 -- uvicorn app:app --port 6002 +``` ### Run Python message publisher with Dapr 1. Install dependencies: - - ```bash cd ./checkout pip3 install -r requirements.txt ``` - 2. Run the Python publisher app with Dapr: - - ```bash dapr run --app-id checkout-sdk --resources-path ../../../components/ -- python3 app.py ``` - +### Stop the apps and clean up ```bash dapr stop --app-id checkout-sdk diff --git a/pub_sub/python/sdk/dapr.yaml b/pub_sub/python/sdk/dapr.yaml new file mode 100644 index 000000000..9bf8c57b5 --- /dev/null +++ b/pub_sub/python/sdk/dapr.yaml @@ -0,0 +1,11 @@ +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-sdk + appDirPath: ./order-processor/ + appPort: 6001 + command: ["uvicorn", "app:app"] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["python3", "app.py"] diff --git a/secrets_management/csharp/sdk/order-processor/Program.csproj b/secrets_management/csharp/sdk/order-processor/Program.csproj index 38b8650fe..dd54cdbe4 100644 --- a/secrets_management/csharp/sdk/order-processor/Program.csproj +++ b/secrets_management/csharp/sdk/order-processor/Program.csproj @@ -6,7 +6,7 @@ - + diff --git a/service_invocation/csharp/http/README.md b/service_invocation/csharp/http/README.md index 6ffe82325..f235865f8 100644 --- a/service_invocation/csharp/http/README.md +++ b/service_invocation/csharp/http/README.md @@ -6,132 +6,97 @@ Visit [this](https://docs.dapr.io/developing-applications/building-blocks/servic This quickstart includes one checkout service: -- Dotnet client service `checkout` +- .NET client service `checkout` And one order processor service: -- Dotnet order-processor service `order-processor` +- .NET order-processor service `order-processor` -### Run Dotnet order-processor with Dapr +## Run all apps with multi-app run template file: -1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. - - -```bash -cd ./order-processor -dotnet restore -dotnet build -``` - - - -2. Run the Dotnet order-processor app with Dapr: +1. Open a new terminal window and run `order-processor` and `checkout` using the multi app run template defined in [dapr.yaml](./dapr.yaml): ```bash -cd ./order-processor -dapr run --app-port 7001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- dotnet run +dapr run -f . ``` - - -### Run Dotnet checkout with Dapr - -1. Open a new terminal window and navigate to the `checkout` directory and install dependencies: - - - -```bash -cd ./checkout -dotnet restore -dotnet build +The terminal console output should look similar to this: + +```text +== APP - order-processor == Order received : Order { orderId = 1 } +== APP - checkout == Order passed: Order { OrderId = 1 } +== APP - order-processor == Order received : Order { orderId = 2 } +== APP - checkout == Order passed: Order { OrderId = 2 } +== APP - order-processor == Order received : Order { orderId = 3 } +== APP - checkout == Order passed: Order { OrderId = 3 } +== APP - order-processor == Order received : Order { orderId = 4 } +== APP - checkout == Order passed: Order { OrderId = 4 } +== APP - order-processor == Order received : Order { orderId = 5 } +== APP - checkout == Order passed: Order { OrderId = 5 } +== APP - order-processor == Order received : Order { orderId = 6 } +== APP - checkout == Order passed: Order { OrderId = 6 } +== APP - order-processor == Order received : Order { orderId = 7 } +== APP - checkout == Order passed: Order { OrderId = 7 } +== APP - order-processor == Order received : Order { orderId = 8 } +== APP - checkout == Order passed: Order { OrderId = 8 } +== APP - order-processor == Order received : Order { orderId = 9 } +== APP - checkout == Order passed: Order { OrderId = 9 } +== APP - order-processor == Order received : Order { orderId = 10 } +== APP - checkout == Order passed: Order { OrderId = 10 } ``` - +2. Stop and clean up application processes -2. Run the Dotnet checkout app with Dapr: - - - ```bash -cd ./checkout -dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- dotnet run +dapr stop -f . ``` - -```bash -dapr stop --app-id order-processor -``` +## Run a single app at a time with Dapr (Optional) -### Start all apps with multi app run template file: +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this. -1. Open a new terminal window and install dependencies for `order-processor` and `checkout` apps: +### Run .NET `order-processor` with Dapr - +1. Open a new terminal window and run the Dotnet order-processor app with Dapr: ```bash cd ./order-processor -dotnet restore -dotnet build -cd ../checkout -dotnet restore -dotnet build +dapr run --app-port 7001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- dotnet run ``` - +### Run .NET `checkout` with Dapr -2. Run the multi app run template: - - +1. Open a new terminal and run the Dotnet checkout app with Dapr: ```bash -dapr run -f . +cd ./checkout +dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- dotnet run ``` - - +### Stop and clean up application processes ```bash -dapr stop -f . -``` \ No newline at end of file +dapr stop --app-id order-processor +dapr stop --app-id checkout +``` diff --git a/service_invocation/go/http/README.md b/service_invocation/go/http/README.md index 7cd9a4bb1..3ab01e0ef 100644 --- a/service_invocation/go/http/README.md +++ b/service_invocation/go/http/README.md @@ -8,21 +8,70 @@ This quickstart includes one checkout service: Go client service `checkout` And one order processor service: Go order-processor service `order-processor` -### Run Go order-processor with Dapr +## Run all apps with multi-app run template file: -1. Run the order-processor app with Dapr in the `order-processor` folder: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Open a new terminal window and run the multi app run template: +```bash +dapr run -f . +``` + +The terminal console output should look similar to this: + +```text +== APP - checkout-http == Published data: {"orderId":1} +== APP - order-processor == Subscriber received: {"orderId":1} +== APP - checkout-http == Published data: {"orderId":2} +== APP - order-processor == Subscriber received: {"orderId":2} +== APP - checkout-http == Published data: {"orderId":3} +== APP - order-processor == Subscriber received: {"orderId":3} +== APP - checkout-http == Published data: {"orderId":4} +== APP - order-processor == Subscriber received: {"orderId":4} +== APP - checkout-http == Published data: {"orderId":5} +== APP - order-processor == Subscriber received: {"orderId":5} +== APP - checkout-http == Published data: {"orderId":6} +== APP - order-processor == Subscriber received: {"orderId":6} +== APP - checkout-http == Published data: {"orderId":7} +== APP - order-processor == Subscriber received: {"orderId":7} +== APP - checkout-http == Published data: {"orderId":8} +== APP - order-processor == Subscriber received: {"orderId":8} +== APP - checkout-http == Published data: {"orderId":9} +== APP - order-processor == Subscriber received: {"orderId":9} +== APP - checkout-http == Published data: {"orderId":10} +== APP - order-processor == Subscriber received: {"orderId":10} +``` + +3. Stop and clean up application processes + +```bash +dapr stop -f . +``` + + +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- go run .` commands. This next section covers how to do this. + +### Run Go order-processor with Dapr + +1. Run the order-processor app with Dapr in the `order-processor` folder: + ```bash cd ./order-processor dapr run \ @@ -33,24 +82,10 @@ dapr run \ -- go run . ``` - - ### Run Go checkout with Dapr 1. Open a new terminal window and navigate to `checkout` directory, then run the Go checkout app with Dapr: - - ```bash cd ./checkout dapr run \ @@ -59,41 +94,9 @@ dapr run \ -- go run . ``` - - -To stop: +### Stop the apps and clean up ```bash dapr stop --app-id checkout dapr stop --app-id order-processor ``` - -### Start all apps with multi app run template file: - -1. Run the multi app run template: - - - -```bash -dapr run -f . -``` - - - -```bash -dapr stop -f . -``` \ No newline at end of file diff --git a/service_invocation/java/http/README.md b/service_invocation/java/http/README.md index 7fa4fe26d..6fa25dbd3 100644 --- a/service_invocation/java/http/README.md +++ b/service_invocation/java/http/README.md @@ -21,120 +21,122 @@ And one order processor service: * [OpenJDK 11](https://jdk.java.net/11/) * [Apache Maven](https://maven.apache.org/install.html) version 3.x. -### Run Java order-processor with Dapr +## Run all apps with multi-app run template file: -1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Open a new terminal window and install dependencies for `order-processor` and `checkout` apps: ```bash cd ./order-processor mvn clean install +cd ../checkout +mvn clean install +cd .. ``` + -2. Run the Java order-processor app with Dapr: +2. Run the multi app run template: ```bash -cd ./order-processor -dapr run --app-id order-processor --app-port 9001 --app-protocol http --dapr-http-port 3501 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar +dapr run -f . ``` - - -### Run Java checkout service with Dapr - -1. Open a new terminal window and navigate to `checkout` directory and install dependencies: +The terminal console output should look similar to this: + +```text +== APP - order-processor == Order received: 1 +== APP - checkout == Order passed: 1 +== APP - order-processor == Order received: 2 +== APP - checkout == Order passed: 2 +== APP - order-processor == Order received: 3 +== APP - checkout == Order passed: 3 +== APP - order-processor == Order received: 4 +== APP - checkout == Order passed: 4 +== APP - order-processor == Order received: 5 +== APP - checkout == Order passed: 5 +== APP - order-processor == Order received: 6 +== APP - checkout == Order passed: 6 +== APP - order-processor == Order received: 7 +== APP - checkout == Order passed: 7 +== APP - order-processor == Order received: 8 +== APP - checkout == Order passed: 8 +== APP - order-processor == Order received: 9 +== APP - checkout == Order passed: 9 +== APP - order-processor == Order received: 10 +== APP - checkout == Order passed: 10 +== APP - order-processor == Order received: 11 +== APP - checkout == Order passed: 11 +== APP - order-processor == Order received: 12 +== APP - checkout == Order passed: 12 +``` - +3. Stop and clean up application processes ```bash -cd ./checkout -mvn clean install +dapr stop -f . ``` -2. Run the Java checkout app with Dapr: +## Run a single app at a time with Dapr (Optional) - +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- java -jar` commands. This next section covers how to do this. + +### Run Java order-processor with Dapr + +1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: ```bash -cd ./checkout -dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar +cd ./order-processor +mvn clean install ``` - +2. Run the Java order-processor app with Dapr: ```bash -dapr stop --app-id checkout -dapr stop --app-id order-processor +dapr run --app-id order-processor --app-port 9001 --app-protocol http --dapr-http-port 3501 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar ``` -### Start all apps with multi app run template file: - -1. Open a new terminal window and install dependencies for `order-processor` and `checkout` apps: +### Run Java checkout service with Dapr - +1. Open a new terminal window and navigate to `checkout` directory and install dependencies: ```bash -cd ./order-processor -mvn clean install -cd ../checkout +cd ./checkout mvn clean install ``` - - -2. Run the multi app run template: - - +2. Run the Java checkout app with Dapr: ```bash -dapr run -f . +dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- java -jar target/CheckoutService-0.0.1-SNAPSHOT.jar ``` - +### Stop and clean up application processes ```bash -dapr stop -f . +dapr stop --app-id checkout +dapr stop --app-id order-processor ``` diff --git a/service_invocation/javascript/http/README.md b/service_invocation/javascript/http/README.md index 16339699e..f33c79a01 100644 --- a/service_invocation/javascript/http/README.md +++ b/service_invocation/javascript/http/README.md @@ -12,123 +12,123 @@ And one order-processor service: - Node order-processor service `order-processor` -### Run Node order-processor with Dapr +## Run all apps with multi-app run template file: -1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Open a new terminal window and install dependencies for `order-processor` and `checkout` apps: ```bash cd ./order-processor npm install +cd ../checkout +npm install +cd .. ``` -3. Run the Node order-processor app with Dapr: +2. Run the multi app run template: ```bash -cd ./order-processor -dapr run --app-port 5001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- npm start +dapr run -f . ``` - - -### Run Node checkout with Dapr - -1. Open a new terminal window and navigate to `checkout` directory and install dependencies: +The terminal console output should look similar to this: + +```text +== APP - order-processor == Order received: { orderId: 1 } +== APP - checkout == Order passed: {"orderId":1} +== APP - order-processor == Order received: { orderId: 2 } +== APP - checkout == Order passed: {"orderId":2} +== APP - order-processor == Order received: { orderId: 3 } +== APP - checkout == Order passed: {"orderId":3} +== APP - order-processor == Order received: { orderId: 4 } +== APP - checkout == Order passed: {"orderId":4} +== APP - order-processor == Order received: { orderId: 5 } +== APP - checkout == Order passed: {"orderId":5} +== APP - order-processor == Order received: { orderId: 6 } +== APP - checkout == Order passed: {"orderId":6} +== APP - order-processor == Order received: { orderId: 7 } +== APP - checkout == Order passed: {"orderId":7} +== APP - order-processor == Order received: { orderId: 8 } +== APP - checkout == Order passed: {"orderId":8} +== APP - order-processor == Order received: { orderId: 9 } +== APP - checkout == Order passed: {"orderId":9} +== APP - order-processor == Order received: { orderId: 10 } +== APP - checkout == Order passed: {"orderId":10} +== APP - order-processor == Order received: { orderId: 11 } +== APP - checkout == Order passed: {"orderId":11} +== APP - order-processor == Order received: { orderId: 12 } +== APP - checkout == Order passed: {"orderId":12} +``` - +3. Stop and clean up application processes ```bash -cd ./checkout -npm install +dapr stop -f . ``` -2. Run the Node checkout app with Dapr: +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- npm start` commands. This next section covers how to do this. + +### Run Node order-processor with Dapr + +1. Open a new terminal window and navigate to `order-processor` directory and install dependencies: - - ```bash -cd ./checkout -dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm start +cd ./order-processor +npm install ``` - +3. Run the Node order-processor app with Dapr: ```bash -dapr stop --app-id checkout -dapr stop --app-id order-processor +dapr run --app-port 5001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- npm start ``` -### Start all apps with multi app run template file: - -1. Open a new terminal window and install dependencies for `order-processor` and `checkout` apps: +### Run Node checkout with Dapr - +1. Open a new terminal window and navigate to `checkout` directory and install dependencies: ```bash -cd ./order-processor -npm install -cd ../checkout +cd ./checkout npm install ``` - - -2. Run the multi app run template: - - +2. Run the Node checkout app with Dapr: ```bash -dapr run -f . +dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm start ``` - +### Stop and clean up application processes ```bash -dapr stop -f . -``` \ No newline at end of file +dapr stop --app-id checkout +dapr stop --app-id order-processor +``` diff --git a/service_invocation/python/http/README.md b/service_invocation/python/http/README.md index 1020e9b80..989d2f3ba 100644 --- a/service_invocation/python/http/README.md +++ b/service_invocation/python/http/README.md @@ -12,108 +12,127 @@ And one order processor service: - Python order-processor service `order-processor` -### Run Python order-processor with Dapr +## Run all apps with multi-app run template file: -1. Install dependencies for `order-processor` app: +This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications. + +1. Open a new terminal window and install dependencies for `order-processor` and `checkout` apps: ```bash cd ./order-processor pip3 install -r requirements.txt +cd ../checkout +pip3 install -r requirements.txt +cd .. ``` -2. Run the Python order-processor app with Dapr: - +2. Run the multi app run template: ```bash -dapr run --app-port 8001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- python3 order-processor/app.py +dapr run -f . ``` - - -### Run Python checkout with Dapr - -1. Open a new terminal window and install dependencies for `checkout` app: +The terminal console output should look similar to this: + +```text +== APP - order-processor == Order received : {"orderId": 1} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 1} +== APP - order-processor == Order received : {"orderId": 2} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 2} +== APP - order-processor == Order received : {"orderId": 3} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 3} +== APP - order-processor == Order received : {"orderId": 4} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 4} +== APP - order-processor == Order received : {"orderId": 5} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 5} +== APP - order-processor == Order received : {"orderId": 6} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 6} +== APP - order-processor == Order received : {"orderId": 7} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 7} +== APP - order-processor == Order received : {"orderId": 8} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 8} +== APP - order-processor == Order received : {"orderId": 9} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 9} +== APP - order-processor == Order received : {"orderId": 10} +== APP - order-processor == 127.0.0.1 - - [DATE] "POST /orders HTTP/1.1" 200 - +== APP - checkout == Order passed: {"orderId": 10} +``` - +3. Stop and clean up application processes ```bash -cd ./checkout -pip3 install -r requirements.txt +dapr stop -f . ``` - -2. Run the Python checkout app with Dapr: +## Run a single app at a time with Dapr (Optional) + +An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- python3 app.py` commands. This next section covers how to do this. + +### Run Python order-processor with Dapr + +1. Install dependencies for `order-processor` app: - - ```bash -dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- python3 checkout/app.py +cd ./order-processor +pip3 install -r requirements.txt ``` - +2. Run the Python order-processor app with Dapr: ```bash -dapr stop --app-id checkout -dapr stop --app-id order-processor +dapr run --app-port 8001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- python3 app.py ``` -### Start all apps with multi app run template file: - -The dependencies are already installed from previous steps. Simply run the multi app run template. It uses `dapr.yaml` file to determine which applications to run. +### Run Python checkout with Dapr - +1. Open a new terminal window and install dependencies for `checkout` app: ```bash -dapr run -f . +cd ./checkout +pip3 install -r requirements.txt ``` - +2. Run the Python checkout app with Dapr: + +```bash +dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- python3 app.py +``` -Finally, stop all: +### Stop and clean up application processes ```bash -dapr stop -f . -``` \ No newline at end of file +dapr stop --app-id checkout +dapr stop --app-id order-processor +``` diff --git a/state_management/csharp/sdk/order-processor/Program.csproj b/state_management/csharp/sdk/order-processor/Program.csproj index 38b8650fe..dd54cdbe4 100644 --- a/state_management/csharp/sdk/order-processor/Program.csproj +++ b/state_management/csharp/sdk/order-processor/Program.csproj @@ -6,7 +6,7 @@ - + diff --git a/tutorials/pub-sub/csharp-subscriber/csharp-subscriber.csproj b/tutorials/pub-sub/csharp-subscriber/csharp-subscriber.csproj index 34b0db0a0..292390229 100644 --- a/tutorials/pub-sub/csharp-subscriber/csharp-subscriber.csproj +++ b/tutorials/pub-sub/csharp-subscriber/csharp-subscriber.csproj @@ -9,7 +9,7 @@ - + diff --git a/workflows/csharp/sdk/order-processor/WorkflowConsoleApp.csproj b/workflows/csharp/sdk/order-processor/WorkflowConsoleApp.csproj index 8ba8656a6..691027bf6 100644 --- a/workflows/csharp/sdk/order-processor/WorkflowConsoleApp.csproj +++ b/workflows/csharp/sdk/order-processor/WorkflowConsoleApp.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/workflows/java/sdk/README.md b/workflows/java/sdk/README.md new file mode 100644 index 000000000..2566ec1ae --- /dev/null +++ b/workflows/java/sdk/README.md @@ -0,0 +1,109 @@ +# Dapr workflows + +In this quickstart, you'll create a simple console application to demonstrate Dapr's workflow programming model and the workflow management API. The console app starts and manages the lifecycle of a workflow that stores and retrieves data in a state store. + +This quickstart includes one project: + +- Java console app `order-processor` + +The quickstart contains 1 workflow to simulate purchasing items from a store, and 5 unique activities within the workflow. These 5 activities are as follows: + +- NotifyActivity: This activity utilizes a logger to print out messages throughout the workflow. These messages notify the user when there is insufficient inventory, their payment couldn't be processed, and more. +- ReserveInventoryActivity: This activity checks the state store to ensure that there is enough inventory present for purchase. +- RequestApprovalActivity: This activity requests approval for orders over a certain threshold +- ProcessPaymentActivity: This activity is responsible for processing and authorizing the payment. +- UpdateInventoryActivity: This activity updates the state store with the new remaining inventory value. + +### Run the order processor workflow + +1. Open a new terminal window and navigate to `order-processor` directory: + + + +```bash +cd ./order-processor +mvn clean install +``` + + +2. Run the console app with Dapr: + + + +```bash +cd ./order-processor +dapr run --app-id WorkflowConsoleApp --resources-path ../../../components/ --dapr-grpc-port 50001 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar io.dapr.quickstarts.workflows.WorkflowConsoleApp +``` + + + +3. Expected output + + +``` +== APP == *** Welcome to the Dapr Workflow console app sample! +== APP == *** Using this app, you can place orders that start workflows. +== APP == Start workflow runtime +== APP == Sep 20, 2023 8:38:30 AM com.microsoft.durabletask.DurableTaskGrpcWorker startAndBlock +== APP == INFO: Durable Task worker is connecting to sidecar at 127.0.0.1:50001. +== APP == ==========Begin the purchase of item:========== +== APP == Starting order workflow, purchasing 10 of cars +== APP == scheduled new workflow instance of OrderProcessingWorkflow with instance ID: 95d33f7c-3af8-4960-ba11-4ecea83b0509 +== APP == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Starting Workflow: io.dapr.quickstarts.workflows.OrderProcessingWorkflow +== APP == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Instance ID(order ID): 95d33f7c-3af8-4960-ba11-4ecea83b0509 +== APP == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Current Orchestration Time: 2023-09-20T08:38:33.248Z +== APP == [Thread-0] INFO io.dapr.workflows.WorkflowContext - Received Order: OrderPayload [itemName=cars, totalCost=150000, quantity=10] +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Received Order: OrderPayload [itemName=cars, totalCost=150000, quantity=10] +== APP == workflow instance 95d33f7c-3af8-4960-ba11-4ecea83b0509 started +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - Reserving inventory for order '95d33f7c-3af8-4960-ba11-4ecea83b0509' of 10 cars +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - There are 100 cars available for purchase +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity - Reserved inventory for order '95d33f7c-3af8-4960-ba11-4ecea83b0509' of 10 cars +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.RequestApprovalActivity - Requesting approval for order: OrderPayload [itemName=cars, totalCost=150000, quantity=10] +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.RequestApprovalActivity - Approved requesting approval for order: OrderPayload [itemName=cars, totalCost=150000, quantity=10] +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Processing payment: 95d33f7c-3af8-4960-ba11-4ecea83b0509 for 10 cars at $150000 +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity - Payment for request ID '95d33f7c-3af8-4960-ba11-4ecea83b0509' processed successfully +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updating inventory for order '95d33f7c-3af8-4960-ba11-4ecea83b0509' of 10 cars +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updated inventory for order '95d33f7c-3af8-4960-ba11-4ecea83b0509': there are now 90 cars left in stock +== APP == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Order completed! : 95d33f7c-3af8-4960-ba11-4ecea83b0509 +== APP == workflow instance 95d33f7c-3af8-4960-ba11-4ecea83b0509 completed, out is: {"processed":true} +``` + +### View workflow output with Zipkin + +For a more detailed view of the workflow activities (duration, progress etc.), try using Zipkin. + +1. Launch Zipkin container - The [openzipkin/zipkin](https://hub.docker.com/r/openzipkin/zipkin/) docker container is launched on running `dapr init`. Check to make sure the container is running. If it's not, launch the Zipkin docker container with the following command. + +```bash +docker run -d -p 9411:9411 openzipkin/zipkin +``` + +2. View Traces in Zipkin UI - In your browser go to http://localhost:9411 to view the workflow trace spans in the Zipkin web UI. The order-processor workflow should be viewable with the following output in the Zipkin web UI. + + + +### What happened? + +When you ran `dapr run --app-id WorkflowConsoleApp --resources-path ../../../components/ --dapr-grpc-port 50001 -- java -jar target/OrderProcessingService-0.0.1-SNAPSHOT.jar io.dapr.quickstarts.workflows.WorkflowConsoleApp` + +1. A unique order ID for the workflow is generated (in the above example, `95d33f7c-3af8-4960-ba11-4ecea83b0509`) and the workflow is scheduled. +2. The `NotifyActivity` workflow activity sends a notification saying an order for 10 cars has been received. +3. The `ReserveInventoryActivity` workflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock. +4. Your workflow starts and notifies you of its status. +5. The `RequestApprovalActivity` workflow activity requests approval for order `95d33f7c-3af8-4960-ba11-4ecea83b0509` +6. The `ProcessPaymentActivity` workflow activity begins processing payment for order `95d33f7c-3af8-4960-ba11-4ecea83b0509` and confirms if successful. +7. The `UpdateInventoryActivity` workflow activity updates the inventory with the current available cars after the order has been processed. +8. The `NotifyActivity` workflow activity sends a notification saying that order `95d33f7c-3af8-4960-ba11-4ecea83b0509` has completed and processed. +9. The workflow terminates as completed and processed. + diff --git a/workflows/java/sdk/img/workflow-trace-spans-zipkin.png b/workflows/java/sdk/img/workflow-trace-spans-zipkin.png new file mode 100644 index 000000000..6564dd4c5 Binary files /dev/null and b/workflows/java/sdk/img/workflow-trace-spans-zipkin.png differ diff --git a/workflows/java/sdk/makefile b/workflows/java/sdk/makefile new file mode 100644 index 000000000..e7a8826bf --- /dev/null +++ b/workflows/java/sdk/makefile @@ -0,0 +1,2 @@ +include ../../../docker.mk +include ../../../validate.mk \ No newline at end of file diff --git a/workflows/java/sdk/order-processor/pom.xml b/workflows/java/sdk/order-processor/pom.xml new file mode 100644 index 000000000..fcf185364 --- /dev/null +++ b/workflows/java/sdk/order-processor/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + com.service + OrderProcessingService + 0.0.1-SNAPSHOT + OrderProcessingService + Demo for Dapr workflow component + + 11 + 11 + 1.6.1 + + + + io.dapr + dapr-sdk-workflows + 0.10.0-SNAPSHOT + + + org.slf4j + slf4j-simple + 1.7.36 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.6.3 + + + + repackage + + + + io.dapr.quickstarts.workflows.WorkflowConsoleApp + + + + + + + + + + + maven-SNAPSHOT + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + + diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/OrderProcessingWorkflow.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/OrderProcessingWorkflow.java new file mode 100644 index 000000000..79f25c4ad --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/OrderProcessingWorkflow.java @@ -0,0 +1,111 @@ +package io.dapr.quickstarts.workflows; + +import org.slf4j.Logger; + +import io.dapr.quickstarts.workflows.activities.NotifyActivity; +import io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity; +import io.dapr.quickstarts.workflows.activities.RequestApprovalActivity; +import io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity; +import io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity; +import io.dapr.quickstarts.workflows.models.ApprovalResult; +import io.dapr.quickstarts.workflows.models.InventoryRequest; +import io.dapr.quickstarts.workflows.models.InventoryResult; +import io.dapr.quickstarts.workflows.models.Notification; +import io.dapr.quickstarts.workflows.models.OrderPayload; +import io.dapr.quickstarts.workflows.models.OrderResult; +import io.dapr.quickstarts.workflows.models.PaymentRequest; +import io.dapr.workflows.Workflow; +import io.dapr.workflows.WorkflowStub; + +public class OrderProcessingWorkflow extends Workflow { + + @Override + public WorkflowStub create() { + return ctx -> { + Logger logger = ctx.getLogger(); + String orderId = ctx.getInstanceId(); + logger.info("Starting Workflow: " + ctx.getName()); + logger.info("Instance ID(order ID): " + orderId); + logger.info("Current Orchestration Time: " + ctx.getCurrentInstant()); + + OrderPayload order = ctx.getInput(OrderPayload.class); + logger.info("Received Order: " + order.toString()); + OrderResult orderResult = new OrderResult(); + orderResult.setProcessed(false); + + // Notify the user that an order has come through + Notification notification = new Notification(); + notification.setMessage("Received Order: " + order.toString()); + ctx.callActivity(NotifyActivity.class.getName(), notification).await(); + + // Determine if there is enough of the item available for purchase by checking + // the inventory + InventoryRequest inventoryRequest = new InventoryRequest(); + inventoryRequest.setRequestId(orderId); + inventoryRequest.setItemName(order.getItemName()); + inventoryRequest.setQuantity(order.getQuantity()); + InventoryResult inventoryResult = ctx.callActivity(ReserveInventoryActivity.class.getName(), + inventoryRequest, InventoryResult.class).await(); + + // If there is insufficient inventory, fail and let the user know + if (!inventoryResult.isSuccess()) { + notification.setMessage("Insufficient inventory for order : " + order.getItemName()); + ctx.callActivity(NotifyActivity.class.getName(), notification).await(); + ctx.complete(orderResult); + return; + } + + // Require orders over a certain threshold to be approved + if (order.getTotalCost() > 5000) { + ApprovalResult approvalResult = ctx.callActivity(RequestApprovalActivity.class.getName(), + order, ApprovalResult.class).await(); + if (approvalResult != ApprovalResult.Approved) { + notification.setMessage("Order " + order.getItemName() + " was not approved."); + ctx.callActivity(NotifyActivity.class.getName(), notification).await(); + ctx.complete(orderResult); + return; + } + } + + // There is enough inventory available so the user can purchase the item(s). + // Process their payment + PaymentRequest paymentRequest = new PaymentRequest(); + paymentRequest.setRequestId(orderId); + paymentRequest.setItemBeingPurchased(order.getItemName()); + paymentRequest.setQuantity(order.getQuantity()); + paymentRequest.setAmount(order.getTotalCost()); + boolean isOK = ctx.callActivity(ProcessPaymentActivity.class.getName(), + paymentRequest, boolean.class).await(); + if (!isOK) { + notification.setMessage("Payment failed for order : " + orderId); + ctx.callActivity(NotifyActivity.class.getName(), notification).await(); + ctx.complete(orderResult); + return; + } + + inventoryResult = ctx.callActivity(UpdateInventoryActivity.class.getName(), + inventoryRequest, InventoryResult.class).await(); + if (!inventoryResult.isSuccess()) { + // If there is an error updating the inventory, refund the user + // paymentRequest.setAmount(-1 * paymentRequest.getAmount()); + // ctx.callActivity(ProcessPaymentActivity.class.getName(), + // paymentRequest).await(); + + // Let users know their payment processing failed + notification.setMessage("Order failed to update inventory! : " + orderId); + ctx.callActivity(NotifyActivity.class.getName(), notification).await(); + ctx.complete(orderResult); + return; + } + + // Let user know their order was processed + notification.setMessage("Order completed! : " + orderId); + ctx.callActivity(NotifyActivity.class.getName(), notification).await(); + + // Complete the workflow with order result is processed + orderResult.setProcessed(true); + ctx.complete(orderResult); + }; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/WorkflowConsoleApp.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/WorkflowConsoleApp.java new file mode 100644 index 000000000..6993b8823 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/WorkflowConsoleApp.java @@ -0,0 +1,132 @@ +/* + * Copyright 2023 The Dapr Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and +limitations under the License. +*/ + +package io.dapr.quickstarts.workflows; + +import java.time.Duration; +import java.util.concurrent.TimeoutException; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.quickstarts.workflows.activities.NotifyActivity; +import io.dapr.quickstarts.workflows.activities.ProcessPaymentActivity; +import io.dapr.quickstarts.workflows.activities.RequestApprovalActivity; +import io.dapr.quickstarts.workflows.activities.ReserveInventoryActivity; +import io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity; +import io.dapr.quickstarts.workflows.models.InventoryItem; +import io.dapr.quickstarts.workflows.models.OrderPayload; +import io.dapr.workflows.client.DaprWorkflowClient; +import io.dapr.workflows.client.WorkflowInstanceStatus; +import io.dapr.workflows.runtime.WorkflowRuntime; +import io.dapr.workflows.runtime.WorkflowRuntimeBuilder; + +public class WorkflowConsoleApp { + + private static final String STATE_STORE_NAME = "statestore-actors"; + + /** + * The main method of this console app. + * + * @param args The port the app will listen on. + * @throws Exception An Exception. + */ + public static void main(String[] args) throws Exception { + System.out.println("*** Welcome to the Dapr Workflow console app sample!"); + System.out.println("*** Using this app, you can place orders that start workflows."); + // Wait for the sidecar to become available + Thread.sleep(5 * 1000); + + // Register the OrderProcessingWorkflow and its activities with the builder. + WorkflowRuntimeBuilder builder = new WorkflowRuntimeBuilder().registerWorkflow(OrderProcessingWorkflow.class); + builder.registerActivity(NotifyActivity.class); + builder.registerActivity(ProcessPaymentActivity.class); + builder.registerActivity(RequestApprovalActivity.class); + builder.registerActivity(ReserveInventoryActivity.class); + builder.registerActivity(UpdateInventoryActivity.class); + + // Build and then start the workflow runtime pulling and executing tasks + try (WorkflowRuntime runtime = builder.build()) { + System.out.println("Start workflow runtime"); + runtime.start(false); + } + + InventoryItem inventory = prepareInventoryAndOrder(); + + DaprWorkflowClient workflowClient = new DaprWorkflowClient(); + try (workflowClient) { + executeWorkflow(workflowClient, inventory); + } + + } + + private static void executeWorkflow(DaprWorkflowClient workflowClient, InventoryItem inventory) { + System.out.println("==========Begin the purchase of item:=========="); + String itemName = inventory.getName(); + int orderQuantity = inventory.getQuantity(); + int totalcost = orderQuantity * inventory.getPerItemCost(); + OrderPayload order = new OrderPayload(); + order.setItemName(itemName); + order.setQuantity(orderQuantity); + order.setTotalCost(totalcost); + System.out.println("Starting order workflow, purchasing " + orderQuantity + " of " + itemName); + + String instanceId = workflowClient.scheduleNewWorkflow(OrderProcessingWorkflow.class, order); + System.out.printf("scheduled new workflow instance of OrderProcessingWorkflow with instance ID: %s%n", + instanceId); + + try { + workflowClient.waitForInstanceStart(instanceId, Duration.ofSeconds(10), false); + System.out.printf("workflow instance %s started%n", instanceId); + } catch (TimeoutException e) { + System.out.printf("workflow instance %s did not start within 10 seconds%n", instanceId); + return; + } + + try { + WorkflowInstanceStatus workflowStatus = workflowClient.waitForInstanceCompletion(instanceId, + Duration.ofSeconds(30), + true); + if (workflowStatus != null) { + System.out.printf("workflow instance completed, out is: %s%n", + workflowStatus.getSerializedOutput()); + } else { + System.out.printf("workflow instance %s not found%n", instanceId); + } + } catch (TimeoutException e) { + System.out.printf("workflow instance %s did not complete within 30 seconds%n", instanceId); + } + + } + + private static InventoryItem prepareInventoryAndOrder() { + // prepare 100 cars in inventory + InventoryItem inventory = new InventoryItem(); + inventory.setName("cars"); + inventory.setPerItemCost(15000); + inventory.setQuantity(100); + DaprClient daprClient = new DaprClientBuilder().build(); + restockInventory(daprClient, inventory); + + // prepare order for 10 cars + InventoryItem order = new InventoryItem(); + order.setName("cars"); + order.setPerItemCost(15000); + order.setQuantity(10); + return order; + } + + private static void restockInventory(DaprClient daprClient, InventoryItem inventory) { + String key = inventory.getName(); + daprClient.saveState(STATE_STORE_NAME, key, inventory).block(); + } +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/NotifyActivity.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/NotifyActivity.java new file mode 100644 index 000000000..7c4f71bc7 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/NotifyActivity.java @@ -0,0 +1,21 @@ +package io.dapr.quickstarts.workflows.activities; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.dapr.quickstarts.workflows.models.Notification; +import io.dapr.workflows.runtime.WorkflowActivity; +import io.dapr.workflows.runtime.WorkflowActivityContext; + +public class NotifyActivity implements WorkflowActivity { + private static Logger logger = LoggerFactory.getLogger(NotifyActivity.class); + + @Override + public Object run(WorkflowActivityContext ctx) { + Notification notification = ctx.getInput(Notification.class); + logger.info(notification.getMessage()); + + return ""; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/ProcessPaymentActivity.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/ProcessPaymentActivity.java new file mode 100644 index 000000000..17dbb8373 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/ProcessPaymentActivity.java @@ -0,0 +1,29 @@ +package io.dapr.quickstarts.workflows.activities; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.dapr.quickstarts.workflows.models.PaymentRequest; +import io.dapr.workflows.runtime.WorkflowActivity; +import io.dapr.workflows.runtime.WorkflowActivityContext; + +public class ProcessPaymentActivity implements WorkflowActivity { + private static Logger logger = LoggerFactory.getLogger(ProcessPaymentActivity.class); + + @Override + public Object run(WorkflowActivityContext ctx) { + PaymentRequest req = ctx.getInput(PaymentRequest.class); + logger.info("Processing payment: {} for {} {} at ${}", + req.getRequestId(), req.getQuantity(), req.getItemBeingPurchased(), req.getAmount()); + + // Simulate slow processing + try { + Thread.sleep(7 * 1000); + } catch (InterruptedException e) { + } + logger.info("Payment for request ID '{}' processed successfully", req.getRequestId()); + + return true; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/RequestApprovalActivity.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/RequestApprovalActivity.java new file mode 100644 index 000000000..1e24ddd9e --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/RequestApprovalActivity.java @@ -0,0 +1,24 @@ +package io.dapr.quickstarts.workflows.activities; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.dapr.quickstarts.workflows.models.ApprovalResult; +import io.dapr.quickstarts.workflows.models.OrderPayload; +import io.dapr.workflows.runtime.WorkflowActivity; +import io.dapr.workflows.runtime.WorkflowActivityContext; + +public class RequestApprovalActivity implements WorkflowActivity { + private static Logger logger = LoggerFactory.getLogger(RequestApprovalActivity.class); + + @Override + public Object run(WorkflowActivityContext ctx) { + OrderPayload order = ctx.getInput(OrderPayload.class); + logger.info("Requesting approval for order: {}", order); + + // hard code to Approved in example + logger.info("Approved requesting approval for order: {}", order); + return ApprovalResult.Approved; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/ReserveInventoryActivity.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/ReserveInventoryActivity.java new file mode 100644 index 000000000..1f0c4292a --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/ReserveInventoryActivity.java @@ -0,0 +1,62 @@ +package io.dapr.quickstarts.workflows.activities; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.domain.State; +import io.dapr.quickstarts.workflows.models.InventoryItem; +import io.dapr.quickstarts.workflows.models.InventoryRequest; +import io.dapr.quickstarts.workflows.models.InventoryResult; +import io.dapr.workflows.runtime.WorkflowActivity; +import io.dapr.workflows.runtime.WorkflowActivityContext; + +public class ReserveInventoryActivity implements WorkflowActivity { + private static Logger logger = LoggerFactory.getLogger(ReserveInventoryActivity.class); + + private static final String STATE_STORE_NAME = "statestore-actors"; + + private DaprClient daprClient; + + public ReserveInventoryActivity() { + this.daprClient = new DaprClientBuilder().build(); + } + + @Override + public Object run(WorkflowActivityContext ctx) { + InventoryRequest inventoryRequest = ctx.getInput(InventoryRequest.class); + logger.info("Reserving inventory for order '{}' of {} {}", + inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName()); + + State inventoryState = daprClient.getState(STATE_STORE_NAME, inventoryRequest.getItemName(), InventoryItem.class).block(); + InventoryItem inventory = inventoryState.getValue(); + + logger.info("There are {} {} available for purchase", + inventory.getQuantity(), inventory.getName()); + + // See if there're enough items to purchase + if (inventory.getQuantity() >= inventoryRequest.getQuantity()) { + // Simulate slow processing + try { + Thread.sleep(2 * 1000); + } catch (InterruptedException e) { + } + logger.info("Reserved inventory for order '{}' of {} {}", + inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName()); + InventoryResult inventoryResult = new InventoryResult(); + inventoryResult.setSuccess(true); + inventoryResult.setInventoryItem(inventory); + return inventoryResult; + } + + // Not enough items. + logger.info("Not enough items to reserve inventory for order '{}' of {} {}", + inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName()); + InventoryResult inventoryResult = new InventoryResult(); + inventoryResult.setSuccess(false); + inventoryResult.setInventoryItem(inventory); + return inventoryResult; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/UpdateInventoryActivity.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/UpdateInventoryActivity.java new file mode 100644 index 000000000..c970f2c37 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/activities/UpdateInventoryActivity.java @@ -0,0 +1,70 @@ +package io.dapr.quickstarts.workflows.activities; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.dapr.client.DaprClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.domain.State; +import io.dapr.quickstarts.workflows.models.InventoryItem; +import io.dapr.quickstarts.workflows.models.InventoryRequest; +import io.dapr.quickstarts.workflows.models.InventoryResult; +import io.dapr.quickstarts.workflows.models.OrderPayload; +import io.dapr.workflows.runtime.WorkflowActivity; +import io.dapr.workflows.runtime.WorkflowActivityContext; + +public class UpdateInventoryActivity implements WorkflowActivity { + private static Logger logger = LoggerFactory.getLogger(UpdateInventoryActivity.class); + + private static final String STATE_STORE_NAME = "statestore-actors"; + + private DaprClient daprClient; + + public UpdateInventoryActivity() { + this.daprClient = new DaprClientBuilder().build(); + } + + @Override + public Object run(WorkflowActivityContext ctx) { + InventoryRequest inventoryRequest = ctx.getInput(InventoryRequest.class); + logger.info("Updating inventory for order '{}' of {} {}", + inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName()); + + // Simulate slow processing + try { + Thread.sleep(2 * 1000); + } catch (InterruptedException e) { + } + + // Determine if there are enough Items for purchase + State inventoryState = daprClient + .getState(STATE_STORE_NAME, inventoryRequest.getItemName(), InventoryItem.class).block(); + InventoryItem inventory = inventoryState.getValue(); + int newQuantity = inventory.getQuantity() - inventoryRequest.getQuantity(); + if (newQuantity < 0) { + logger.info("Not enough inventory for order '{}' of {} {}, there are only {} {}", + inventoryRequest.getRequestId(), inventoryRequest.getQuantity(), inventoryRequest.getItemName(), + inventory.getQuantity(), inventory.getName()); + + InventoryResult inventoryResult = new InventoryResult(); + inventoryResult.setSuccess(false); + return inventoryResult; + } + + // Update the statestore with the new amount of paper clips + OrderPayload updatedOrderPayload = new OrderPayload(); + updatedOrderPayload.setItemName(inventoryRequest.getItemName()); + updatedOrderPayload.setQuantity(newQuantity); + daprClient.saveState(STATE_STORE_NAME, inventoryRequest.getItemName(), inventoryState.getEtag(), + updatedOrderPayload, null).block(); + + logger.info("Updated inventory for order '{}': there are now {} {} left in stock", + inventoryRequest.getRequestId(), newQuantity, inventoryRequest.getItemName()); + // in addition to print to std out for validation + System.out.println("there are now " + newQuantity + " " + inventoryRequest.getItemName() + " left in stock"); + InventoryResult inventoryResult = new InventoryResult(); + inventoryResult.setSuccess(true); + return inventoryResult; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/ApprovalRequired.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/ApprovalRequired.java new file mode 100644 index 000000000..4ee5a45f7 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/ApprovalRequired.java @@ -0,0 +1,19 @@ +package io.dapr.quickstarts.workflows.models; + +public class ApprovalRequired { + private boolean approval; + + public boolean isApproval() { + return approval; + } + + public void setApproval(boolean approval) { + this.approval = approval; + } + + @Override + public String toString() { + return "ApprovalRequired [approval=" + approval + "]"; + } + +} \ No newline at end of file diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/ApprovalResult.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/ApprovalResult.java new file mode 100644 index 000000000..71ea7d5da --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/ApprovalResult.java @@ -0,0 +1,7 @@ +package io.dapr.quickstarts.workflows.models; + +public enum ApprovalResult { + Unspecified, + Approved, + Rejected +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryItem.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryItem.java new file mode 100644 index 000000000..62261a3e7 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryItem.java @@ -0,0 +1,36 @@ +package io.dapr.quickstarts.workflows.models; + +public class InventoryItem { + private String name; + private int perItemCost; + private int quantity; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPerItemCost() { + return perItemCost; + } + + public void setPerItemCost(int perItemCost) { + this.perItemCost = perItemCost; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + @Override + public String toString() { + return "InventoryItem [name=" + name + ", perItemCost=" + perItemCost + ", quantity=" + quantity + "]"; + } +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryRequest.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryRequest.java new file mode 100644 index 000000000..cee70d6ab --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryRequest.java @@ -0,0 +1,37 @@ +package io.dapr.quickstarts.workflows.models; + +public class InventoryRequest { + + private String requestId; + private String itemName; + private int quantity; + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + @Override + public String toString() { + return "InventoryRequest [requestId=" + requestId + ", itemName=" + itemName + ", quantity=" + quantity + "]"; + } +} \ No newline at end of file diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryResult.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryResult.java new file mode 100644 index 000000000..249bd9b1d --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/InventoryResult.java @@ -0,0 +1,27 @@ +package io.dapr.quickstarts.workflows.models; + +public class InventoryResult { + private boolean success; + private InventoryItem inventoryItem; + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public InventoryItem getInventoryItem() { + return inventoryItem; + } + + public void setInventoryItem(InventoryItem inventoryItem) { + this.inventoryItem = inventoryItem; + } + + @Override + public String toString() { + return "InventoryResult [success=" + success + ", inventoryItem=" + inventoryItem + "]"; + } +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/Notification.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/Notification.java new file mode 100644 index 000000000..d77f9d186 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/Notification.java @@ -0,0 +1,19 @@ +package io.dapr.quickstarts.workflows.models; + +public class Notification { + private String message; + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return "Notification [message=" + message + "]"; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/OrderPayload.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/OrderPayload.java new file mode 100644 index 000000000..01f748519 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/OrderPayload.java @@ -0,0 +1,38 @@ +package io.dapr.quickstarts.workflows.models; + +public class OrderPayload { + + private String itemName; + private int totalCost; + private int quantity; + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public int getTotalCost() { + return totalCost; + } + + public void setTotalCost(int totalCost) { + this.totalCost = totalCost; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + @Override + public String toString() { + return "OrderPayload [itemName=" + itemName + ", totalCost=" + totalCost + ", quantity=" + quantity + "]"; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/OrderResult.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/OrderResult.java new file mode 100644 index 000000000..a32d12137 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/OrderResult.java @@ -0,0 +1,19 @@ +package io.dapr.quickstarts.workflows.models; + +public class OrderResult { + private boolean processed; + + public boolean isProcessed() { + return processed; + } + + public void setProcessed(boolean processed) { + this.processed = processed; + } + + @Override + public String toString() { + return "OrderResult [processed=" + processed + "]"; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/PaymentRequest.java b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/PaymentRequest.java new file mode 100644 index 000000000..350e354c2 --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/java/io/dapr/quickstarts/workflows/models/PaymentRequest.java @@ -0,0 +1,47 @@ +package io.dapr.quickstarts.workflows.models; + +public class PaymentRequest { + private String requestId; + private String itemBeingPurchased; + private int amount; + private int quantity; + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getItemBeingPurchased() { + return itemBeingPurchased; + } + + public void setItemBeingPurchased(String itemBeingPurchased) { + this.itemBeingPurchased = itemBeingPurchased; + } + + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + @Override + public String toString() { + return "PaymentRequest [requestId=" + requestId + ", itemBeingPurchased=" + itemBeingPurchased + ", amount=" + amount + + ", quantity=" + quantity + "]"; + } + +} diff --git a/workflows/java/sdk/order-processor/src/main/resources/simplelogger.properties b/workflows/java/sdk/order-processor/src/main/resources/simplelogger.properties new file mode 100644 index 000000000..32ca7250a --- /dev/null +++ b/workflows/java/sdk/order-processor/src/main/resources/simplelogger.properties @@ -0,0 +1 @@ +org.slf4j.simpleLogger.logFile=System.out