You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daprdocs/content/en/concepts/building-blocks-concept.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,5 +28,5 @@ Dapr provides the following building blocks:
28
28
| [**Secrets**]({{< ref "secrets-overview.md" >}}) | `/v1.0/secrets` | Dapr provides a secrets building block API and integrates with secret stores such as public cloud stores, local stores and Kubernetes to store the secrets. Services can call the secrets API to retrieve secrets, for example to get a connection string to a database.
29
29
| [**Configuration**]({{< ref "configuration-api-overview.md" >}}) | `/v1.0/configuration` | The Configuration API enables you to retrieve and subscribe to application configuration items for supported configuration stores. This enables an application to retrieve specific configuration information, for example, at start up or when configuration changes are made in the store.
30
30
| [**Distributed lock**]({{< ref "distributed-lock-api-overview.md" >}}) | `/v1.0-alpha1/lock` | The distributed lock API enables you to take a lock on a resource so that multiple instances of an application can access the resource without conflicts and provide consistency guarantees.
31
-
| [**Workflows**]({{< ref "workflow-overview.md" >}}) | `/v1.0-alpha1/workflow` | The Workflow API enables you to define long running, persistent processes or data flows that span multiple microservices using Dapr workflows or workflow components. The Workflow API can be combined with other Dapr API building blocks. For example, a workflow can call another service with service invocation or retrieve secrets, providing flexibility and portability.
31
+
| [**Workflows**]({{< ref "workflow-overview.md" >}}) | `/v1.0-beta1/workflow` | The Workflow API enables you to define long running, persistent processes or data flows that span multiple microservices using Dapr workflows or workflow components. The Workflow API can be combined with other Dapr API building blocks. For example, a workflow can call another service with service invocation or retrieve secrets, providing flexibility and portability.
32
32
| [**Cryptography**]({{< ref "cryptography-overview.md" >}}) | `/v1.0-alpha1/crypto` | The Cryptography API enables you to perform cryptographic operations, such as encrypting and decrypting messages, without exposing keys to your application.
description: "Learn how to develop and author workflows"
7
7
---
8
8
9
+
{{% alert title="Note" color="primary" %}}
10
+
Dapr Workflow is currently in beta. [See known limitations for {{% dapr-latest-version cli="true" %}}]({{< ref "workflow-overview.md#limitations" >}}).
11
+
{{% /alert %}}
12
+
9
13
This article provides a high-level overview of how to author workflows that are executed by the Dapr Workflow engine.
10
14
11
15
{{% alert title="Note" color="primary" %}}
@@ -30,7 +34,25 @@ The Dapr sidecar doesn’t load any workflow definitions. Rather, the sidecar si
30
34
31
35
[Workflow activities]({{< ref "workflow-features-concepts.md#workflow-activites" >}}) are the basic unit of work in a workflow and are the tasks that get orchestrated in the business process.
32
36
33
-
{{< tabs ".NET" Python >}}
37
+
{{< tabs Python ".NET" Java >}}
38
+
39
+
{{% codetab %}}
40
+
41
+
<!--python-->
42
+
43
+
Define the workflow activities you'd like your workflow to perform. Activities are a function definition and can take inputs and outputs. The following example creates a counter (activity) called `hello_act` that notifies users of the current counter value. `hello_act` is a function derived from a class called `WorkflowActivityContext`.
print(f'New counter value is: {counter}!', flush=True)
50
+
```
51
+
52
+
[See the `hello_act` workflow activity in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL40C1-L43C59)
53
+
54
+
55
+
{{% /codetab %}}
34
56
35
57
{{% codetab %}}
36
58
@@ -102,29 +124,76 @@ public class ProcessPaymentActivity : WorkflowActivity<PaymentRequest, object>
102
124
103
125
{{% codetab %}}
104
126
105
-
<!--python-->
127
+
<!--java-->
106
128
107
-
Define the workflow activities you'd like your workflow to perform. Activities are a function definition and can take inputs and outputs. The following example creates a counter (activity) called `hello_act` that notifies users of the current counter value. `hello_act` is a function derived from a class called `WorkflowActivityContext`.
129
+
Define the workflow activities you'd like your workflow to perform. Activities are wrapped in the public `DemoWorkflowActivity` class, which implements the workflow activities.
var message = ctx.getInput(DemoActivityInput.class).getMessage();
141
+
var newMessage = message +" World!, from Activity";
142
+
logger.info("Message Received from input: "+ message);
143
+
logger.info("Sending message to output: "+ newMessage);
144
+
145
+
logger.info("Sleeping for 5 seconds to simulate long running operation...");
146
+
147
+
try {
148
+
TimeUnit.SECONDS.sleep(5);
149
+
} catch (InterruptedException e) {
150
+
thrownewRuntimeException(e);
151
+
}
152
+
153
+
154
+
logger.info("Activity finished");
155
+
156
+
var output =newDemoActivityOutput(message, newMessage);
157
+
logger.info("Activity returned: "+ output);
158
+
159
+
return output;
160
+
}
161
+
}
162
+
```
163
+
164
+
[See the Java SDK workflow activity example in context.](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflowActivity.java)
118
165
119
166
{{% /codetab %}}
120
167
168
+
121
169
{{< /tabs >}}
122
170
123
171
## Write the workflow
124
172
125
173
Next, register and call the activites in a workflow.
126
174
127
-
{{< tabs ".NET" Python >}}
175
+
{{< tabs Python ".NET" Java >}}
176
+
177
+
{{% codetab %}}
178
+
179
+
<!--python-->
180
+
181
+
The `hello_world_wf` function is derived from a class called `DaprWorkflowContext` with input and output parameter types. It also includes a `yield` statement that does the heavy lifting of the workflow and calls the workflow activities.
[See the `hello_world_wf` workflow in context.](https://github.com/dapr/python-sdk/blob/master/examples/demo_workflow/app.py#LL32C1-L38C51)
194
+
195
+
196
+
{{% /codetab %}}
128
197
129
198
{{% codetab %}}
130
199
@@ -171,103 +240,42 @@ The `OrderProcessingWorkflow` class is derived from a base class called `Workflo
171
240
172
241
{{% codetab %}}
173
242
174
-
<!--python-->
175
-
176
-
The `hello_world_wf` function is derived from a class called `DaprWorkflowContext` with input and output parameter types. It also includes a `yield` statement that does the heavy lifting of the workflow and calls the workflow activities.
[In the following `Program.cs` example](https://github.com/dapr/dotnet-sdk/blob/master/examples/Workflow/WorkflowConsoleApp/Program.cs), for a basic ASP.NET order processing application using the .NET SDK, your project code would include:
206
-
207
-
- A NuGet package called `Dapr.Workflow` to receive the .NET SDK capabilities
208
-
- A builder with an extension method called `AddDaprWorkflow`
209
-
- This will allow you to register workflows and workflow activities (tasks that workflows can schedule)
210
-
- HTTP API calls
211
-
- One for submitting a new order
212
-
- One for checking the status of an existing order
213
-
214
-
```csharp
215
-
usingDapr.Workflow;
216
-
//...
256
+
// Build and then start the workflow runtime pulling and executing tasks
257
+
try (WorkflowRuntime runtime = builder.build()) {
258
+
System.out.println("Start workflow runtime");
259
+
runtime.start();
260
+
}
217
261
218
-
// Dapr Workflows are registered as part of the service configuration
219
-
builder.Services.AddDaprWorkflow(options=>
220
-
{
221
-
// Note that it's also possible to register a lambda function as the workflow
[See the Java SDK workflow in context.](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflowWorker.java)
returnResults.NotFound($"No order with ID = '{orderId}' was found.");
255
-
}
270
+
{{% /codetab %}}
256
271
257
-
varhttpResponsePayload=new
258
-
{
259
-
details=state.ReadInputAs<OrderPayload>(),
260
-
status=state.RuntimeStatus.ToString(),
261
-
result=state.ReadOutputAs<OrderResult>(),
262
-
};
272
+
{{< /tabs >}}
263
273
264
-
//...
265
-
}).WithName("GetOrderInfoEndpoint");
274
+
## Write the application
266
275
267
-
app.Run();
268
-
```
276
+
Finally, compose the application using the workflow.
269
277
270
-
{{% /codetab %}}
278
+
{{< tabs Python ".NET" Java >}}
271
279
272
280
{{% codetab %}}
273
281
@@ -356,6 +364,124 @@ if __name__ == '__main__':
356
364
```
357
365
358
366
367
+
{{% /codetab %}}
368
+
369
+
{{% codetab %}}
370
+
371
+
<!--csharp-->
372
+
373
+
[In the following `Program.cs` example](https://github.com/dapr/dotnet-sdk/blob/master/examples/Workflow/WorkflowConsoleApp/Program.cs), for a basic ASP.NET order processing application using the .NET SDK, your project code would include:
374
+
375
+
- A NuGet package called `Dapr.Workflow` to receive the .NET SDK capabilities
376
+
- A builder with an extension method called `AddDaprWorkflow`
377
+
- This will allow you to register workflows and workflow activities (tasks that workflows can schedule)
378
+
- HTTP API calls
379
+
- One for submitting a new order
380
+
- One for checking the status of an existing order
381
+
382
+
```csharp
383
+
usingDapr.Workflow;
384
+
//...
385
+
386
+
// Dapr Workflows are registered as part of the service configuration
387
+
builder.Services.AddDaprWorkflow(options=>
388
+
{
389
+
// Note that it's also possible to register a lambda function as the workflow
returnResults.NotFound($"No order with ID = '{orderId}' was found.");
423
+
}
424
+
425
+
varhttpResponsePayload=new
426
+
{
427
+
details=state.ReadInputAs<OrderPayload>(),
428
+
status=state.RuntimeStatus.ToString(),
429
+
result=state.ReadOutputAs<OrderResult>(),
430
+
};
431
+
432
+
//...
433
+
}).WithName("GetOrderInfoEndpoint");
434
+
435
+
app.Run();
436
+
```
437
+
438
+
{{% /codetab %}}
439
+
440
+
{{% codetab %}}
441
+
442
+
<!--java-->
443
+
444
+
[As in the following example](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflow.java), a hello-world application using the Java SDK and Dapr Workflow would include:
445
+
446
+
- A Java package called `io.dapr.workflows.client` to receive the Java SDK client capabilities.
447
+
- An import of `io.dapr.workflows.Workflow`
448
+
- The `DemoWorkflow` class which extends `Workflow`
449
+
- Creating the workflow with input and output.
450
+
- API calls. In the example below, these calls start and call the workflow activities.
var input =newDemoActivityInput("Hello Activity!");
476
+
var output = ctx.callActivity(DemoWorkflowActivity.class.getName(), input, DemoActivityOutput.class).await();
477
+
// ...
478
+
};
479
+
}
480
+
}
481
+
```
482
+
483
+
[See the full Java SDK workflow example in context.](https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/workflows/DemoWorkflow.java)
484
+
359
485
{{% /codetab %}}
360
486
361
487
@@ -377,5 +503,6 @@ Now that you've authored a workflow, learn how to manage it.
0 commit comments