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,7 +684,7 @@ Key Points:
### 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:
```java
@ -692,18 +692,18 @@ public class CrossAppWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
System.out.println("=== WORKFLOW STARTING ===");
ctx.getLogger().info("=== WORKFLOW STARTING ===");
ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName());
System.out.println("Workflow name: " + ctx.getName());
System.out.println("Workflow instance ID: " + ctx.getInstanceId());
ctx.getLogger().info("Workflow name: " + ctx.getName());
ctx.getLogger().info("Workflow instance ID: " + ctx.getInstanceId());
String input = ctx.getInput(String.class);
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
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(
App2TransformActivity.class.getName(),
input,
@ -713,7 +713,7 @@ public class CrossAppWorkflow implements Workflow {
// Call another activity in a different app
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(
App3FinalizeActivity.class.getName(),
crossAppResult,
@ -721,14 +721,15 @@ public class CrossAppWorkflow implements Workflow {
String.class
).await();
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);
System.out.println("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
ctx.getLogger().info("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
ctx.complete(finalResult);
};
}
}
```
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
public WorkflowStub create() {
return ctx -> {
System.out.println("=== WORKFLOW STARTING ===");
ctx.getLogger().info("=== WORKFLOW STARTING ===");
ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName());
System.out.println("Workflow name: " + ctx.getName());
System.out.println("Workflow instance ID: " + ctx.getInstanceId());
ctx.getLogger().info("Workflow name: " + ctx.getName());
ctx.getLogger().info("Workflow instance ID: " + ctx.getInstanceId());
String input = ctx.getInput(String.class);
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
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(
App2TransformActivity.class.getName(),
input,
@ -46,7 +46,7 @@ public class CrossAppWorkflow implements Workflow {
// Call another activity in a different app
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(
App3FinalizeActivity.class.getName(),
crossAppResult,
@ -54,10 +54,10 @@ public class CrossAppWorkflow implements Workflow {
String.class
).await();
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);
System.out.println("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
ctx.getLogger().info("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
ctx.complete(finalResult);
};
}