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/java-sdk-docs/java-workflow/java-workflow-howto.md
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -249,34 +249,33 @@ Exiting DemoWorkflowClient.
249
249
250
250
## Advanced features
251
251
252
-
### Task Execution Keys
252
+
### Task Execution Ids
253
253
254
-
Task execution keys are unique identifiers generated by the durabletask-java library. They are stored in the `WorkflowActivityContext` and can be used to track and manage the execution of workflow activities. They are particularly useful for:
254
+
Task execution ids are unique identifiers generated by the durabletask-java library. They are stored in the `WorkflowActivityContext` and can be used to track and manage the execution of workflow activities. They are particularly useful for:
255
+
256
+
**Idempotency**: Ensuring activities are not executed multiple times for the same task
255
257
256
-
1.**Idempotency**: Ensuring activities are not executed multiple times for the same task
257
-
2.**State Management**: Tracking the state of activity execution
258
-
3.**Error Handling**: Managing retries and failures in a controlled manner
259
258
260
259
Here's an example of how to use task execution keys in your workflow activities:
Copy file name to clipboardExpand all lines: examples/src/main/java/io/dapr/examples/workflows/README.md
+138-1Lines changed: 138 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -711,4 +711,141 @@ Started a new external-event model workflow with instance ID: 23410d96-1afe-4698
711
711
workflow instance with ID: 23410d96-1afe-4698-9fcd-c01c1e0db255 completed.
712
712
```
713
713
714
-
### Idempotency Pattern
714
+
### Idempotency Pattern
715
+
716
+
The idempotency pattern ensures that activities can be safely retried without causing unintended side effects. This pattern is crucial when dealing with potentially unreliable external services or when network failures might cause activities to be retried. In this example, we demonstrate how to use task execution IDs to implement idempotent activities that return consistent results across retries.
717
+
718
+
The `IdempotentWorkflow` class defines the workflow with retry policies and calls activities with specific limits. The workflow uses a shared key store to track task execution attempts. See the code snippet below:
The `IdempotentActivity` class implements the idempotency logic using task execution IDs. Each task execution has a unique ID that remains consistent across retries, allowing the activity to track its state and ensure idempotent behavior. See the code snippet below:
Started a new chaining model workflow with instance ID: 7f8e92a4-5b3c-4d1f-8e2a-9b8c7d6e5f4g
841
+
workflow instance with ID: 7f8e92a4-5b3c-4d1f-8e2a-9b8c7d6e5f4g completed with result: [3, 2, 1]
842
+
```
843
+
844
+
Key Points:
845
+
1.**Task Execution ID**: Each activity call has a unique task execution ID that remains consistent across retries
846
+
2.**Retry Policy**: The workflow defines a retry policy with exponential backoff and maximum attempts
847
+
3.**State Tracking**: The activity uses a shared key store to track the execution state for each task execution ID
848
+
4.**Controlled Failure**: The activity intentionally fails until it reaches the specified limit, demonstrating retry behavior
849
+
5.**Idempotent Result**: Once the limit is reached, subsequent retries with the same task execution ID return the same result
850
+
851
+
This pattern is essential for building resilient workflows that can handle transient failures without causing duplicate operations or inconsistent state.
0 commit comments