feat: Add compensation workflow pattern to Spring Boot examples#1696
feat: Add compensation workflow pattern to Spring Boot examples#1696siri-varma wants to merge 10 commits intodapr:masterfrom
Conversation
Port the BookTrip compensation (Saga) workflow from the plain Java examples into the Spring Boot workflow patterns module, adding @Component-annotated activities and a /wfp/compensation REST endpoint. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Siri Varma Vegiraju <svegiraju@Siris-MacBook-Pro.local>
There was a problem hiding this comment.
Pull request overview
Adds a Spring Boot “compensation / Saga” workflow pattern example (BookTrip) to the workflows/patterns module, along with a REST endpoint to trigger it.
Changes:
- Introduces
BookTripWorkflowimplementing a simple saga with compensating activities. - Adds booking and cancellation workflow activities as Spring components.
- Exposes a new
POST /wfp/compensationendpoint to run the workflow and return its output.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelHotelActivity.java | Adds hotel-cancellation activity for compensation flow |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelFlightActivity.java | Adds flight-cancellation activity for compensation flow |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelCarActivity.java | Adds car-cancellation activity for compensation flow |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookTripWorkflow.java | Implements saga-style orchestration with compensation retries |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookHotelActivity.java | Adds hotel booking activity used by the workflow |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookFlightActivity.java | Adds flight booking activity used by the workflow |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookCarActivity.java | Adds car booking activity that intentionally fails to trigger compensation |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/WorkflowPatternsRestController.java | Adds POST /wfp/compensation endpoint to run the new workflow |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
|
@siri-varma I am a bit against this way of doing compensations, that's why I've created this example: https://github.com/diagrid-labs/workflow-patterns-spring-boot?tab=readme-ov-file#compensate-on-error-example I think that having an arraylist inside the workflow itself is a hack and should be avoided. Check this specifically: https://github.com/diagrid-labs/workflow-patterns-spring-boot/blob/main/workflows/src/main/java/io/dapr/springboot/workflows/compensateonerror/CompensateWhenErrorWorkflow.java#L40 Check the example and let me know if you have any questions, I would rather have an example following that approach in the SDK than a port from other languages. |
salaboy
left a comment
There was a problem hiding this comment.
Check my comment in the PR
Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1696 +/- ##
=========================================
Coverage 76.77% 76.77%
Complexity 2259 2259
=========================================
Files 241 241
Lines 7066 7066
Branches 740 740
=========================================
Hits 5425 5425
Misses 1277 1277
Partials 364 364 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@javier-aliaga, @salaboy addressed all the comments on this PR |
There was a problem hiding this comment.
Pull request overview
Adds a Spring Boot version of the “BookTrip” compensation (Saga) workflow pattern to the workflow patterns example app, and refactors the plain Java compensation example to reduce duplicated compensation logic.
Changes:
- Introduces
BookTripWorkflowplus booking/cancellation activities as Spring components underwfp/compensation. - Exposes a new
POST /wfp/compensationendpoint to run the compensation demo workflow in the Spring Boot patterns app. - Refactors the non-Spring “examples” compensation workflow to use a new
CompensationHelper.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelHotelActivity.java | Adds hotel cancellation activity for compensation demo. |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelFlightActivity.java | Adds flight cancellation activity for compensation demo. |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/CancelCarActivity.java | Adds car cancellation activity for compensation demo. |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookTripWorkflow.java | Adds Spring Boot orchestration implementing compensation logic + retries for compensations. |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookHotelActivity.java | Adds hotel booking activity for compensation demo. |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookFlightActivity.java | Adds flight booking activity for compensation demo. |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/compensation/BookCarActivity.java | Adds car booking activity (forces failure to demonstrate compensation). |
| spring-boot-examples/workflows/patterns/src/main/java/io/dapr/springboot/examples/wfp/WorkflowPatternsRestController.java | Adds POST /wfp/compensation endpoint to run the new workflow. |
| examples/src/main/java/io/dapr/examples/workflows/compensation/CompensationHelper.java | Adds helper to register and execute compensations in reverse order. |
| examples/src/main/java/io/dapr/examples/workflows/compensation/BookTripWorkflow.java | Refactors plain Java example to use CompensationHelper for compensation execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Port the BookTrip compensation (Saga) workflow from the plain Java examples into the Spring Boot workflow patterns module, adding @Component-annotated activities and a /wfp/compensation REST endpoint.
Description
Please explain the changes you've made
Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: #1395
#1395
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: