mirror of https://github.com/dapr/java-sdk.git
sysout -> ctx.logger
Signed-off-by: Cassandra Coyle <cassie@diagrid.io>
This commit is contained in:
parent
4836553caf
commit
8a8b36e9a9
|
|
@ -684,51 +684,52 @@ 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
|
||||
public class CrossAppWorkflow implements Workflow {
|
||||
@Override
|
||||
public WorkflowStub create() {
|
||||
return ctx -> {
|
||||
System.out.println("=== WORKFLOW STARTING ===");
|
||||
ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName());
|
||||
System.out.println("Workflow name: " + ctx.getName());
|
||||
System.out.println("Workflow instance ID: " + ctx.getInstanceId());
|
||||
return ctx -> {
|
||||
ctx.getLogger().info("=== WORKFLOW STARTING ===");
|
||||
ctx.getLogger().info("Starting CrossAppWorkflow: " + ctx.getName());
|
||||
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);
|
||||
String input = ctx.getInput(String.class);
|
||||
ctx.getLogger().info("CrossAppWorkflow received 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...");
|
||||
String crossAppResult = ctx.callActivity(
|
||||
App2TransformActivity.class.getName(),
|
||||
input,
|
||||
new WorkflowTaskOptions("app2"),
|
||||
String.class
|
||||
).await();
|
||||
// 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("About to call cross-app activity in app2...");
|
||||
String crossAppResult = ctx.callActivity(
|
||||
App2TransformActivity.class.getName(),
|
||||
input,
|
||||
new WorkflowTaskOptions("app2"),
|
||||
String.class
|
||||
).await();
|
||||
|
||||
// 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...");
|
||||
String finalResult = ctx.callActivity(
|
||||
App3FinalizeActivity.class.getName(),
|
||||
crossAppResult,
|
||||
new WorkflowTaskOptions("app3"),
|
||||
String.class
|
||||
).await();
|
||||
ctx.getLogger().info("Final cross-app activity result: " + finalResult);
|
||||
System.out.println("Final cross-app activity result: " + finalResult);
|
||||
|
||||
ctx.getLogger().info("CrossAppWorkflow finished with: " + finalResult);
|
||||
System.out.println("=== WORKFLOW COMPLETING WITH: " + finalResult + " ===");
|
||||
ctx.complete(finalResult);
|
||||
};
|
||||
// Call another activity in a different app
|
||||
ctx.getLogger().info("Calling cross-app activity in 'app3'...");
|
||||
ctx.getLogger().info("About to call cross-app activity in app3...");
|
||||
String finalResult = ctx.callActivity(
|
||||
App3FinalizeActivity.class.getName(),
|
||||
crossAppResult,
|
||||
new WorkflowTaskOptions("app3"),
|
||||
String.class
|
||||
).await();
|
||||
ctx.getLogger().info("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("=== 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:
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue