sysout -> ctx.logger

Signed-off-by: Cassandra Coyle <cassie@diagrid.io>
This commit is contained in:
Cassandra Coyle 2025-08-13 10:49:02 -05:00 committed by Javier Aliaga
parent 4836553caf
commit 8a8b36e9a9
2 changed files with 43 additions and 42 deletions

View File

@ -684,51 +684,52 @@ Key Points:
### Cross-App Pattern ### Cross-App Pattern
The cross-app pattern allows workflows to call activities that are hosted in different Dapr applications. This is useful for microservices architectures where activities are distributed across multiple services, or multi-tenant applications where activities are isolated by app ID. The cross-app pattern allows workflows to call activities that are hosted in different Dapr applications. This is useful for microservices architectures allowing multiple applications to host activities that can be orchestrated by Dapr Workflows.
The `CrossAppWorkflow` class defines the workflow. It demonstrates calling activities in different apps using the `appId` parameter in `WorkflowTaskOptions`. See the code snippet below: The `CrossAppWorkflow` class defines the workflow. It demonstrates calling activities in different apps using the `appId` parameter in `WorkflowTaskOptions`. See the code snippet below:
```java ```java
public class CrossAppWorkflow implements Workflow { public class CrossAppWorkflow implements Workflow {
@Override @Override
public WorkflowStub create() { public WorkflowStub create() {
return ctx -> { return ctx -> {
System.out.println("=== WORKFLOW STARTING ==="); ctx.getLogger().info("=== WORKFLOW STARTING ===");
ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName()); ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName());
System.out.println("Workflow name: " + ctx.getName()); ctx.getLogger().info("Workflow name: " + ctx.getName());
System.out.println("Workflow instance ID: " + ctx.getInstanceId()); ctx.getLogger().info("Workflow instance ID: " + ctx.getInstanceId());
String input = ctx.getInput(String.class); String input = ctx.getInput(String.class);
ctx.getLogger().info("CrossAppWorkflow received input: " + input); ctx.getLogger().info("CrossAppWorkflow received input: " + input);
System.out.println("Workflow input: " + input); ctx.getLogger().info("Workflow input: " + input);
// Call an activity in another app by passing in an active appID to the WorkflowTaskOptions // Call an activity in another app by passing in an active appID to the WorkflowTaskOptions
ctx.getLogger().info("Calling cross-app activity in 'app2'..."); ctx.getLogger().info("Calling cross-app activity in 'app2'...");
System.out.println("About to call cross-app activity in app2..."); ctx.getLogger().info("About to call cross-app activity in app2...");
String crossAppResult = ctx.callActivity( String crossAppResult = ctx.callActivity(
App2TransformActivity.class.getName(), App2TransformActivity.class.getName(),
input, input,
new WorkflowTaskOptions("app2"), new WorkflowTaskOptions("app2"),
String.class String.class
).await(); ).await();
// Call another activity in a different app // Call another activity in a different app
ctx.getLogger().info("Calling cross-app activity in 'app3'..."); ctx.getLogger().info("Calling cross-app activity in 'app3'...");
System.out.println("About to call cross-app activity in app3..."); ctx.getLogger().info("About to call cross-app activity in app3...");
String finalResult = ctx.callActivity( String finalResult = ctx.callActivity(
App3FinalizeActivity.class.getName(), App3FinalizeActivity.class.getName(),
crossAppResult, crossAppResult,
new WorkflowTaskOptions("app3"), new WorkflowTaskOptions("app3"),
String.class String.class
).await(); ).await();
ctx.getLogger().info("Final cross-app activity result: " + finalResult); ctx.getLogger().info("Final cross-app activity result: " + finalResult);
System.out.println("Final cross-app activity result: " + finalResult); ctx.getLogger().info("Final cross-app activity result: " + finalResult);
ctx.getLogger().info("CrossAppWorkflow finished with: " + finalResult); ctx.getLogger().info("CrossAppWorkflow finished with: " + finalResult);
System.out.println("=== WORKFLOW COMPLETING WITH: " + finalResult + " ==="); ctx.getLogger().info("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
ctx.complete(finalResult); ctx.complete(finalResult);
}; };
} }
} }
``` ```
The `App2TransformActivity` class defines an activity in app2 that transforms the input string. See the code snippet below: The `App2TransformActivity` class defines an activity in app2 that transforms the input string. See the code snippet below:

View File

@ -25,18 +25,18 @@ public class CrossAppWorkflow implements Workflow {
@Override @Override
public WorkflowStub create() { public WorkflowStub create() {
return ctx -> { return ctx -> {
System.out.println("=== WORKFLOW STARTING ==="); ctx.getLogger().info("=== WORKFLOW STARTING ===");
ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName()); ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName());
System.out.println("Workflow name: " + ctx.getName()); ctx.getLogger().info("Workflow name: " + ctx.getName());
System.out.println("Workflow instance ID: " + ctx.getInstanceId()); ctx.getLogger().info("Workflow instance ID: " + ctx.getInstanceId());
String input = ctx.getInput(String.class); String input = ctx.getInput(String.class);
ctx.getLogger().info("CrossAppWorkflow received input: " + input); ctx.getLogger().info("CrossAppWorkflow received input: " + input);
System.out.println("Workflow input: " + input); ctx.getLogger().info("Workflow input: " + input);
// Call an activity in another app by passing in an active appID to the WorkflowTaskOptions // Call an activity in another app by passing in an active appID to the WorkflowTaskOptions
ctx.getLogger().info("Calling cross-app activity in 'app2'..."); ctx.getLogger().info("Calling cross-app activity in 'app2'...");
System.out.println("About to call cross-app activity in app2..."); ctx.getLogger().info("About to call cross-app activity in app2...");
String crossAppResult = ctx.callActivity( String crossAppResult = ctx.callActivity(
App2TransformActivity.class.getName(), App2TransformActivity.class.getName(),
input, input,
@ -46,7 +46,7 @@ public class CrossAppWorkflow implements Workflow {
// Call another activity in a different app // Call another activity in a different app
ctx.getLogger().info("Calling cross-app activity in 'app3'..."); ctx.getLogger().info("Calling cross-app activity in 'app3'...");
System.out.println("About to call cross-app activity in app3..."); ctx.getLogger().info("About to call cross-app activity in app3...");
String finalResult = ctx.callActivity( String finalResult = ctx.callActivity(
App3FinalizeActivity.class.getName(), App3FinalizeActivity.class.getName(),
crossAppResult, crossAppResult,
@ -54,10 +54,10 @@ public class CrossAppWorkflow implements Workflow {
String.class String.class
).await(); ).await();
ctx.getLogger().info("Final cross-app activity result: " + finalResult); ctx.getLogger().info("Final cross-app activity result: " + finalResult);
System.out.println("Final cross-app activity result: " + finalResult); ctx.getLogger().info("Final cross-app activity result: " + finalResult);
ctx.getLogger().info("CrossAppWorkflow finished with: " + finalResult); ctx.getLogger().info("CrossAppWorkflow finished with: " + finalResult);
System.out.println("=== WORKFLOW COMPLETING WITH: " + finalResult + " ==="); ctx.getLogger().info("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
ctx.complete(finalResult); ctx.complete(finalResult);
}; };
} }