From 0049babfd8df173a1d1482c3e048645dc976de20 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 9 Feb 2023 17:19:59 -0600 Subject: [PATCH 1/4] add section for workflow in .NET SDK docs Signed-off-by: Hannah Hunter --- daprdocs/content/en/dotnet-sdk-docs/_index.md | 7 +++++++ .../content/en/dotnet-sdk-docs/dotnet-actors/_index.md | 2 +- .../content/en/dotnet-sdk-docs/dotnet-workflow/_index.md | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/_index.md diff --git a/daprdocs/content/en/dotnet-sdk-docs/_index.md b/daprdocs/content/en/dotnet-sdk-docs/_index.md index d89dfbe49..01058b2c4 100644 --- a/daprdocs/content/en/dotnet-sdk-docs/_index.md +++ b/daprdocs/content/en/dotnet-sdk-docs/_index.md @@ -57,6 +57,13 @@ Put the Dapr .NET SDK to the test. Walk through the .NET quickstarts and tutoria +
+
+
Workflow
+

Create and manage workflows with state, reminders/timers, and methods in .NET.

+ +
+
## More information diff --git a/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md b/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md index b2e172e47..05ad4a0b7 100644 --- a/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md +++ b/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md @@ -2,7 +2,7 @@ type: docs title: "Dapr actors .NET SDK" linkTitle: "Actors" -weight: 40000 +weight: 30000 description: Get up and running with the Dapr .NET SDK --- diff --git a/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/_index.md b/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/_index.md new file mode 100644 index 000000000..df8244ac3 --- /dev/null +++ b/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/_index.md @@ -0,0 +1,8 @@ +--- +type: docs +title: "Dapr Workflow .NET SDK" +linkTitle: "Workflow" +weight: 40000 +description: Get up and running with Dapr Workflow and the Dapr .NET SDK +--- + From 8b280bbdcdeeec7747a68b19f56793a983b79b0d Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 10 Feb 2023 17:43:11 -0600 Subject: [PATCH 2/4] add initial draft Signed-off-by: Hannah Hunter --- .../dotnet-workflow/dotnet-workflow-howto.md | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md diff --git a/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md b/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md new file mode 100644 index 000000000..f8df14959 --- /dev/null +++ b/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md @@ -0,0 +1,153 @@ +--- +type: docs +title: "How to: Author and manage Dapr Workflow in the .NET SDK" +linkTitle: "How to: Author & manage workflows" +weight: 100000 +description: Learn how to author and manage Dapr Workflow using the .NET SDK +--- + +Let's create a Dapr workflow (`Workflow`) and invoke it using the console. In the provided purchase order processing workflow example, the console prompts provide directions on how to both purchase and restock items. In this guide, you will: + +- Create an ASP.NET application ([WorkflowConsoleApp](./WorkflowConsoleApp)). +- Utilize the .NET workflow SDK and API calls to start and query workflow instances. + +In the .NET example project: +- The main `Program.cs` file contains the setup of the app, including the registration of the workflow and workflow activities. +- The workflow definition is found in the `Workflows` directory. +- The workflow activity definitions are found in the `Activities` directory. + +## Prerequisites + +- [.NET 6+](https://dotnet.microsoft.com/download) installed +- [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/) +- [Initialized Dapr environment](https://docs.dapr.io/getting-started/install-dapr-selfhost/) +- [Dapr .NET SDK](https://github.com/dapr/dotnet-sdk/) + +## Run the application + +You'll need two terminal windows to run the workflow web app locally. + +In the first terminal window, from the `WorkflowConsoleApp` directory, run the following command to start the program itself: + +```sh +dotnet run +``` + +Next, in a separate terminal window, start the Dapr sidecar: + +```sh +dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500 +``` + +Dapr listens for HTTP requests at `http://localhost:3500`. + +## Start a workflow + +To start a workflow, you have two options: + +1. Follow the directions from the console prompts. +1. Use the workflow API and send a request to Dapr directly. + +This guide focuses on the workflow API option. Examples are included both below and in the `WorkflowConsoleApp`>`demo.http` file. + +Run the following command to start a workflow. + +{{< tabs "Linux/MacOS" "Windows">}} + +{{% codetab %}} + +```bash +curl -i -X POST http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/1234/start \ + -H "Content-Type: application/json" \ + -d '{ "input" : {"Name": "Paperclips", "TotalCost": 99.95, "Quantity": 1}}' +``` + +{{% /codetab %}} + +{{% codetab %}} + +```powershell +curl -i -X POST http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/1234/start ` + -H "Content-Type: application/json" ` + -d '{ "input" : {"Name": "Paperclips", "TotalCost": 99.95, "Quantity": 1}}' +``` + +{{% /codetab %}} + +{{< /tabs >}} + +Things to note: + +- The body of the curl request is the purchase order information used as the input of the workflow. +- The "1234" in the commands represents the unique identifier for the workflow run and can be replaced with any identifier of your choosing. + + +If successful, you should see a response like the following: + +```json +{"instance_id":"1234"} +``` + +Send an HTTP request to get the status of the workflow that was started: + +```bash +curl -i -X GET http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/1234 +``` + +The workflow is designed to take several seconds to complete. If the workflow hasn't completed when you issue the HTTP request, you'll see the following JSON response (formatted for readability) with workflow status as `RUNNING`: + +```json +{ + "WFInfo": { + "instance_id": "1234" + }, + "start_time": "2023-02-02T23:34:53Z", + "metadata": { + "dapr.workflow.custom_status": "", + "dapr.workflow.input": "{\"Name\":\"Paperclips\",\"Quantity\":1,\"TotalCost\":99.95}", + "dapr.workflow.last_updated": "2023-02-02T23:35:07Z", + "dapr.workflow.name": "OrderProcessingWorkflow", + "dapr.workflow.output": "{\"Processed\":true}", + "dapr.workflow.runtime_status": "RUNNING" + } +} +``` + +Once the workflow has completed running, you should see the following output, indicating that it has reached the `COMPLETED` status: + +```json +{ + "WFInfo": { + "instance_id": "1234" + }, + "start_time": "2023-02-02T23:34:53Z", + "metadata": { + "dapr.workflow.custom_status": "", + "dapr.workflow.input": "{\"Name\":\"Paperclips\",\"Quantity\":1,\"TotalCost\":99.95}", + "dapr.workflow.last_updated": "2023-02-02T23:35:07Z", + "dapr.workflow.name": "OrderProcessingWorkflow", + "dapr.workflow.output": "{\"Processed\":true}", + "dapr.workflow.runtime_status": "COMPLETED" + } +} +``` + +When the workflow has completed, the stdout of the workflow app should look like: + +```log +info: WorkflowConsoleApp.Activities.NotifyActivity[0] + Received order 1234 for Paperclips at $99.95 +info: WorkflowConsoleApp.Activities.ReserveInventoryActivity[0] + Reserving inventory: 1234, Paperclips, 1 +info: WorkflowConsoleApp.Activities.ProcessPaymentActivity[0] + Processing payment: 1234, 99.95, USD +info: WorkflowConsoleApp.Activities.NotifyActivity[0] + Order 1234 processed successfully! +``` + +If you have Zipkin configured for Dapr locally on your machine, then you can view the workflow trace spans in the Zipkin web UI (typically at http://localhost:9411/zipkin/). + +## Next steps + +- [Try the Dapr Workflow quickstart]({{< ref workflow-quickstart.md >}}) +- [Learn more about Dapr Workflow]({{< ref workflow-overview.md >}}) \ No newline at end of file From 84145b361e3ca60f555415898326e04f957e70bd Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 10 Feb 2023 17:44:15 -0600 Subject: [PATCH 3/4] edit from Mark Signed-off-by: Hannah Hunter --- daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md b/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md index 05ad4a0b7..bd0a37447 100644 --- a/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md +++ b/daprdocs/content/en/dotnet-sdk-docs/dotnet-actors/_index.md @@ -3,7 +3,7 @@ type: docs title: "Dapr actors .NET SDK" linkTitle: "Actors" weight: 30000 -description: Get up and running with the Dapr .NET SDK +description: Get up and running with the Dapr actors .NET SDK --- With the Dapr actor package, you can interact with Dapr virtual actors from a .NET application. From ed949ad073405c70bc110ada86f11befd440a944 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 24 Feb 2023 10:25:28 -0600 Subject: [PATCH 4/4] quick pass and update from hal and chris Signed-off-by: Hannah Hunter --- daprdocs/content/en/dotnet-sdk-docs/_index.md | 2 +- .../dotnet-workflow/dotnet-workflow-howto.md | 48 +++++++++++++------ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/daprdocs/content/en/dotnet-sdk-docs/_index.md b/daprdocs/content/en/dotnet-sdk-docs/_index.md index 01058b2c4..65d818723 100644 --- a/daprdocs/content/en/dotnet-sdk-docs/_index.md +++ b/daprdocs/content/en/dotnet-sdk-docs/_index.md @@ -60,7 +60,7 @@ Put the Dapr .NET SDK to the test. Walk through the .NET quickstarts and tutoria
Workflow
-

Create and manage workflows with state, reminders/timers, and methods in .NET.

+

Create and manage workflows that work with other Dapr APIs in .NET.

diff --git a/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md b/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md index f8df14959..d19aee6dd 100644 --- a/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md +++ b/daprdocs/content/en/dotnet-sdk-docs/dotnet-workflow/dotnet-workflow-howto.md @@ -6,9 +6,9 @@ weight: 100000 description: Learn how to author and manage Dapr Workflow using the .NET SDK --- -Let's create a Dapr workflow (`Workflow`) and invoke it using the console. In the provided purchase order processing workflow example, the console prompts provide directions on how to both purchase and restock items. In this guide, you will: +Let's create a Dapr workflow and invoke it using the console. In the [provided order processing workflow example](https://github.com/dapr/dotnet-sdk/tree/master/examples/Workflow), the console prompts provide directions on how to both purchase and restock items. In this guide, you will: -- Create an ASP.NET application ([WorkflowConsoleApp](./WorkflowConsoleApp)). +- Create a .NET console application ([WorkflowConsoleApp](./WorkflowConsoleApp)). - Utilize the .NET workflow SDK and API calls to start and query workflow instances. In the .NET example project: @@ -23,23 +23,42 @@ In the .NET example project: - [Initialized Dapr environment](https://docs.dapr.io/getting-started/install-dapr-selfhost/) - [Dapr .NET SDK](https://github.com/dapr/dotnet-sdk/) -## Run the application -You'll need two terminal windows to run the workflow web app locally. +## Set up the environment -In the first terminal window, from the `WorkflowConsoleApp` directory, run the following command to start the program itself: +Clone the [.NET SDK repo](https://github.com/dapr/dotnet-sdk). + +```sh +git clone https://github.com/dapr/dotnet-sdk.git +``` + +From the .NET SDK root directory, navigate to the Dapr Workflow example. + +```sh +cd examples/Workflow +``` + +## Run the application locally + +To run the Dapr application, you need to start the .NET program and a Dapr sidecar. Navigate to the `WorkflowConsoleApp` directory. + +```sh +cd WorkflowConsoleApp +``` + +Start the program. ```sh dotnet run ``` -Next, in a separate terminal window, start the Dapr sidecar: +In a new terminal, navigate again to the `WorkflowConsoleApp` directory and run the Dapr sidecar alongside the program. ```sh dapr run --app-id wfapp --dapr-grpc-port 4001 --dapr-http-port 3500 ``` -Dapr listens for HTTP requests at `http://localhost:3500`. +> Dapr listens for HTTP requests at `http://localhost:3500` and internal workflow gRPC requests at `http://localhost:4001`. ## Start a workflow @@ -48,7 +67,14 @@ To start a workflow, you have two options: 1. Follow the directions from the console prompts. 1. Use the workflow API and send a request to Dapr directly. -This guide focuses on the workflow API option. Examples are included both below and in the `WorkflowConsoleApp`>`demo.http` file. +This guide focuses on the workflow API option. + +{{% alert title="Note" color="primary" %}} + - You can find the commands below in the `WorkflowConsoleApp`/`demo.http` file. + - The body of the curl request is the purchase order information used as the input of the workflow. + - The "1234" in the commands represents the unique identifier for the workflow and can be replaced with any identifier of your choosing. +{{% /alert %}} + Run the following command to start a workflow. @@ -76,12 +102,6 @@ curl -i -X POST http://localhost:3500/v1.0-alpha1/workflows/dapr/OrderProcessing {{< /tabs >}} -Things to note: - -- The body of the curl request is the purchase order information used as the input of the workflow. -- The "1234" in the commands represents the unique identifier for the workflow run and can be replaced with any identifier of your choosing. - - If successful, you should see a response like the following: ```json