mirror of https://github.com/dapr/quickstarts.git
				
				
				
			Merge branch 'master' into workflow-tutorials
This commit is contained in:
		
						commit
						2f154ea31b
					
				| 
						 | 
				
			
			@ -47,7 +47,7 @@ The terminal console output should look similar to this, where:
 | 
			
		|||
 | 
			
		||||
<!-- END_STEP -->
 | 
			
		||||
 | 
			
		||||
2. Stop and clean up application processes.
 | 
			
		||||
Stop and clean up application processes.
 | 
			
		||||
 | 
			
		||||
<!-- STEP
 | 
			
		||||
name: Stop multi-app run
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ The terminal console output should look similar to this, where:
 | 
			
		|||
 | 
			
		||||
<!-- END_STEP -->
 | 
			
		||||
 | 
			
		||||
2. Stop and clean up application processes.
 | 
			
		||||
Stop and clean up application processes.
 | 
			
		||||
 | 
			
		||||
<!-- STEP
 | 
			
		||||
name: Stop multi-app run
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,3 +1,15 @@
 | 
			
		|||
# ------------------------------------------------------------
 | 
			
		||||
# Copyright 2025 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.
 | 
			
		||||
# ------------------------------------------------------------
 | 
			
		||||
import logging
 | 
			
		||||
import requests
 | 
			
		||||
import os
 | 
			
		||||
| 
						 | 
				
			
			@ -10,7 +22,6 @@ base_url = os.getenv('BASE_URL', 'http://localhost') + ':' + os.getenv(
 | 
			
		|||
CONVERSATION_COMPONENT_NAME = 'echo'
 | 
			
		||||
 | 
			
		||||
input = {
 | 
			
		||||
		'name': 'echo',
 | 
			
		||||
		'inputs': [{'content':'What is dapr?'}],
 | 
			
		||||
		'parameters': {},
 | 
			
		||||
		'metadata': {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
# Dapr Conversation API (Python HTTP)
 | 
			
		||||
# Dapr Conversation API (Python SDK)
 | 
			
		||||
 | 
			
		||||
In this quickstart, you'll send an input to a mock Large Language Model (LLM) using Dapr's Conversation API. This API is responsible for providing one consistent API entry point to talk to underlying LLM providers.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +59,7 @@ The terminal console output should look similar to this, where:
 | 
			
		|||
 | 
			
		||||
<!-- END_STEP -->
 | 
			
		||||
 | 
			
		||||
2. Stop and clean up application processes.
 | 
			
		||||
3. Stop and clean up application processes.
 | 
			
		||||
 | 
			
		||||
<!-- STEP
 | 
			
		||||
name: Stop multi-app run 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,7 +68,7 @@ dapr run -f .
 | 
			
		|||
4. Stop Dapr workflow with CTRL-C or:
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
dapr stop -f .
 | 
			
		||||
    dapr stop -f .
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### View workflow output with Zipkin
 | 
			
		||||
| 
						 | 
				
			
			@ -83,11 +83,11 @@ launched on running `dapr init`.
 | 
			
		|||
 | 
			
		||||
### What happened? 
 | 
			
		||||
 | 
			
		||||
When you ran the above comands:
 | 
			
		||||
When you ran the above commands:
 | 
			
		||||
 | 
			
		||||
1. An OrderPayload is made containing one car.
 | 
			
		||||
2. A unique order ID for the workflow is generated (in the above example, `b4cb2687-1af0-4f8d-9659-eb6389c07ade`) and the workflow is scheduled.
 | 
			
		||||
3. The `NotifyActivity` workflow activity sends a notification saying an order for 10 cars has been received.
 | 
			
		||||
3. The `NotifyActivity` workflow activity sends a notification saying an order for 1 car has been received.
 | 
			
		||||
4. The `VerifyInventoryActivity` workflow activity checks the inventory data, determines if you can supply the ordered item, and responds with the number of cars in stock.
 | 
			
		||||
5. The total cost of the order is 5000, so the workflow will not call the `RequestApprovalActivity` activity.
 | 
			
		||||
6. The `ProcessPaymentActivity` workflow activity begins processing payment for order `b4cb2687-1af0-4f8d-9659-eb6389c07ade` and confirms if successful.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ package main
 | 
			
		|||
type OrderPayload struct {
 | 
			
		||||
	ItemName  string `json:"item_name"`
 | 
			
		||||
	TotalCost int    `json:"total_cost"`
 | 
			
		||||
	Quantity  int    `json:"quanity"`
 | 
			
		||||
	Quantity  int    `json:"quantity"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type OrderResult struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -13,13 +13,13 @@ type OrderResult struct {
 | 
			
		|||
type InventoryItem struct {
 | 
			
		||||
	ItemName    string `json:"item_name"`
 | 
			
		||||
	PerItemCost int    `json:"per_item_cost"`
 | 
			
		||||
	Quantity    int    `json:"quanity"`
 | 
			
		||||
	Quantity    int    `json:"quantity"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type InventoryRequest struct {
 | 
			
		||||
	RequestID string `json:"request_id"`
 | 
			
		||||
	ItemName  string `json:"item_name"`
 | 
			
		||||
	Quantity  int    `json:"quanity"`
 | 
			
		||||
	Quantity  int    `json:"quantity"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type InventoryResult struct {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,7 +35,7 @@ cd ..
 | 
			
		|||
name: Run order-processor service
 | 
			
		||||
expected_stdout_lines:
 | 
			
		||||
  - '== APP - order-processor == there are now 9 cars left in stock'
 | 
			
		||||
  - '== APP - order-processor == workflow instance completed, out is: {"processed":true}'
 | 
			
		||||
  - '== APP - order-processor == Workflow instance completed, out is: {"processed":true}'
 | 
			
		||||
expected_stderr_lines:
 | 
			
		||||
output_match_mode: substring
 | 
			
		||||
background: true
 | 
			
		||||
| 
						 | 
				
			
			@ -85,7 +85,7 @@ dapr run -f .
 | 
			
		|||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.UpdateInventoryActivity - Updated inventory for order 'd1bf548b-c854-44af-978e-90c61ed88e3c': there are now 9 cars left in stock
 | 
			
		||||
== APP - order-processor == there are now 9 cars left in stock
 | 
			
		||||
== APP - order-processor == [Thread-0] INFO io.dapr.quickstarts.workflows.activities.NotifyActivity - Order completed! : d1bf548b-c854-44af-978e-90c61ed88e3c
 | 
			
		||||
== APP - order-processor == workflow instance completed, out is: {"processed":true}
 | 
			
		||||
== APP - order-processor == Workflow instance completed, out is: {"processed":true}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
4. Stop Dapr workflow with CTRL-C or:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@
 | 
			
		|||
 * 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.
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
package io.dapr.quickstarts.workflows;
 | 
			
		||||
| 
						 | 
				
			
			@ -73,22 +73,22 @@ public class WorkflowConsoleApp {
 | 
			
		|||
    System.out.println("==========Begin the purchase of item:==========");
 | 
			
		||||
    String itemName = inventory.getName();
 | 
			
		||||
    int orderQuantity = inventory.getQuantity();
 | 
			
		||||
    int totalcost = orderQuantity * inventory.getPerItemCost();
 | 
			
		||||
    int totalCost = orderQuantity * inventory.getPerItemCost();
 | 
			
		||||
    OrderPayload order = new OrderPayload();
 | 
			
		||||
    order.setItemName(itemName);
 | 
			
		||||
    order.setQuantity(orderQuantity);
 | 
			
		||||
    order.setTotalCost(totalcost);
 | 
			
		||||
    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",
 | 
			
		||||
    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);
 | 
			
		||||
      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);
 | 
			
		||||
      System.out.printf("Workflow instance %s did not start within 10 seconds%n", instanceId);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -97,13 +97,13 @@ public class WorkflowConsoleApp {
 | 
			
		|||
          Duration.ofSeconds(30),
 | 
			
		||||
          true);
 | 
			
		||||
      if (workflowStatus != null) {
 | 
			
		||||
        System.out.printf("workflow instance completed, out is: %s%n",
 | 
			
		||||
        System.out.printf("Workflow instance completed, out is: %s%n",
 | 
			
		||||
            workflowStatus.getSerializedOutput());
 | 
			
		||||
      } else {
 | 
			
		||||
        System.out.printf("workflow instance %s not found%n", instanceId);
 | 
			
		||||
        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);
 | 
			
		||||
      System.out.printf("Workflow instance %s did not complete within 30 seconds%n", instanceId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -112,12 +112,12 @@ public class WorkflowConsoleApp {
 | 
			
		|||
    // prepare 10 cars in inventory
 | 
			
		||||
    InventoryItem inventory = new InventoryItem();
 | 
			
		||||
    inventory.setName("cars");
 | 
			
		||||
    inventory.setPerItemCost(50000);
 | 
			
		||||
    inventory.setPerItemCost(5000);
 | 
			
		||||
    inventory.setQuantity(10);
 | 
			
		||||
    DaprClient daprClient = new DaprClientBuilder().build();
 | 
			
		||||
    restockInventory(daprClient, inventory);
 | 
			
		||||
 | 
			
		||||
    // prepare order for 10 cars
 | 
			
		||||
    // prepare order for 1 car
 | 
			
		||||
    InventoryItem order = new InventoryItem();
 | 
			
		||||
    order.setName("cars");
 | 
			
		||||
    order.setPerItemCost(5000);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -127,7 +127,7 @@ export const orderProcessingWorkflow: TWorkflow = async function* (ctx: Workflow
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  const orderCompletedNotification: OrderNotification = {
 | 
			
		||||
    message: `order ${orderId} processed successfully!`,
 | 
			
		||||
    message: `Order ${orderId} processed successfully!`,
 | 
			
		||||
  };
 | 
			
		||||
  yield ctx.callActivity(notifyActivity, orderCompletedNotification);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue