From f5f78a3df7634fef4a55fa078950c9bf9aef352b Mon Sep 17 00:00:00 2001 From: Albert Callarisa Date: Tue, 9 Sep 2025 15:16:57 +0200 Subject: [PATCH] Shortened sample code to show just the necessary pieces Signed-off-by: Albert Callarisa --- .../workflow/workflow-multi-app.md | 135 ++---------------- 1 file changed, 14 insertions(+), 121 deletions(-) diff --git a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-multi-app.md b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-multi-app.md index 21dfb9f7f..6894881d7 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-multi-app.md +++ b/daprdocs/content/en/developing-applications/building-blocks/workflow/workflow-multi-app.md @@ -56,60 +56,20 @@ It is paramount that there is co-ordination between the teams owning the differe Diagram showing multi-application call activity workflow pattern -The following example shows how to execute activities on different target app IDs. +The following example shows how to execute the activity `ActivityA` on the target app `App2`. {{< tabpane text=true >}} {{% tab "Go" %}} ```go -package main - -import ( - "context" - "log" - - "github.com/dapr/durabletask-go/backend" - "github.com/dapr/durabletask-go/client" - "github.com/dapr/durabletask-go/task" - dapr "github.com/dapr/go-sdk/client" -) - -func main() { - ctx := context.Background() - - registry := task.NewTaskRegistry() - if err := registry.AddOrchestrator(TestWorkflow); err != nil { - log.Fatal(err) - } - - daprClient, err := dapr.NewClient() - if err != nil { - log.Fatal(err) - } - - client := client.NewTaskHubGrpcClient(daprClient.GrpcClientConn(), backend.DefaultLogger()) - if err := client.StartWorkItemListener(ctx, registry); err != nil { - log.Fatal(err) - } - - id, err := client.ScheduleNewOrchestration(ctx, "TestWorkflow") - if err != nil { - log.Fatal(err) - } - - if _, err = client.WaitForOrchestrationCompletion(ctx, id); err != nil { - log.Fatal(err) - } -} - func TestWorkflow(ctx *task.OrchestrationContext) (any, error) { var output string - err := ctx.CallActivity("my-other-activity", + err := ctx.CallActivity("ActivityA", task.WithActivityInput("my-input"), - // Here we set custom target app ID which will execute this activity. - task.WithActivityAppID("my-other-app-id"), + task.WithActivityAppID("App2"), // Here we set the target app ID which will execute this activity. ).Await(&output) + if err != nil { return nil, err } @@ -127,41 +87,14 @@ public class CrossAppWorkflow implements Workflow { @Override public WorkflowStub create() { return ctx -> { - var logger = ctx.getLogger(); - logger.info("=== WORKFLOW STARTING ==="); - logger.info("Starting CrossAppWorkflow: {}", ctx.getName()); - logger.info("Workflow name: {}", ctx.getName()); - logger.info("Workflow instance ID: {}", ctx.getInstanceId()); - - String input = ctx.getInput(String.class); - logger.info("CrossAppWorkflow received input: {}", input); - logger.info("Workflow input: {}", input); - - // Call an activity in another app by passing in an active appID to the WorkflowTaskOptions - logger.info("Calling cross-app activity in 'app2'..."); - logger.info("About to call cross-app activity in app2..."); - String crossAppResult = ctx.callActivity( - App2TransformActivity.class.getName(), - input, - new WorkflowTaskOptions("app2"), + String output = ctx.callActivity( + "ActivityA", + "my-input", + new WorkflowTaskOptions("App2"), // Here we set the target app ID which will execute this activity. String.class ).await(); - // Call another activity in a different app - logger.info("Calling cross-app activity in 'app3'..."); - logger.info("About to call cross-app activity in app3..."); - String finalResult = ctx.callActivity( - App3FinalizeActivity.class.getName(), - crossAppResult, - new WorkflowTaskOptions("app3"), - String.class - ).await(); - logger.info("Final cross-app activity result: {}", finalResult); - logger.info("Final cross-app activity result: {}", finalResult); - - logger.info("CrossAppWorkflow finished with: {}", finalResult); - logger.info("=== WORKFLOW COMPLETING WITH: {} ===" , finalResult); - ctx.complete(finalResult); + ctx.complete(output); }; } } @@ -173,62 +106,22 @@ public class CrossAppWorkflow implements Workflow { ## Multi-application child workflow example -The following example shows how to execute child workflows on different target app IDs. - Diagram showing multi-application child workflow pattern +The following example shows how to execute the child workflow `Workflow2` on the target app `App2`. + {{< tabpane text=true >}} {{% tab "Go" %}} ```go -package main - -import ( - "context" - "log" - - "github.com/dapr/durabletask-go/backend" - "github.com/dapr/durabletask-go/client" - "github.com/dapr/durabletask-go/task" - dapr "github.com/dapr/go-sdk/client" -) - -func main() { - ctx := context.Background() - - registry := task.NewTaskRegistry() - if err := registry.AddOrchestrator(TestWorkflow); err != nil { - log.Fatal(err) - } - - daprClient, err := dapr.NewClient() - if err != nil { - log.Fatal(err) - } - - client := client.NewTaskHubGrpcClient(daprClient.GrpcClientConn(), backend.DefaultLogger()) - if err := client.StartWorkItemListener(ctx, registry); err != nil { - log.Fatal(err) - } - - id, err := client.ScheduleNewOrchestration(ctx, "TestWorkflow") - if err != nil { - log.Fatal(err) - } - - if _, err = client.WaitForOrchestrationCompletion(ctx, id); err != nil { - log.Fatal(err) - } -} - func TestWorkflow(ctx *task.OrchestrationContext) (any, error) { var output string - err := ctx.CallSubOrchestrator("my-sub-orchestration", + err := ctx.CallSubOrchestrator("Workflow2", task.WithSubOrchestratorInput("my-input"), - // Here we set custom target app ID which will execute this child workflow. - task.WithSubOrchestratorAppID("my-sub-app-id"), + task.WithSubOrchestratorAppID("App2"), // Here we set the target app ID which will execute this child workflow. ).Await(&output) + if err != nil { return nil, err }