Skip to content

Commit eddc02d

Browse files
committed
cleaning up names
1 parent 29306fd commit eddc02d

File tree

15 files changed

+534
-0
lines changed

15 files changed

+534
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Task Chaining Pattern
2+
3+
This tutorial demonstrates how to chain multiple tasks together as a sequence in a workflow. For more information about the task chaining pattern see the [Dapr docs](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-patterns/#task-chaining).
4+
5+
## Inspect the code
6+
7+
Open the `ChainingWorkflow.java` file in the `tutorials/workflow/java/task-chaining/src/main/java/io/dapr/springboot/examples/wfp/chain` folder. This file contains the definition for the workflow.
8+
9+
```mermaid
10+
graph LR
11+
SW((Start
12+
Workflow))
13+
A1[Activity1]
14+
A2[Activity2]
15+
A3[Activity3]
16+
EW((End
17+
Workflow))
18+
SW --> A1
19+
A1 --> A2
20+
A2 --> A3
21+
A3 --> EW
22+
```
23+
24+
25+
## Run the tutorial
26+
27+
1. Use a terminal to navigate to the `tutorials/workflow/java/task-chaining` folder.
28+
2. Build and run the project using Maven.
29+
30+
```bash
31+
mvn spring-boot:test-run
32+
```
33+
34+
3Use the POST request in the [`chaining.http`](./chaining.http) file to start the workflow, or use this cURL command:
35+
36+
```bash
37+
curl -i --request POST http://localhost:8080/start
38+
```
39+
40+
The input for the workflow is a string with the value `This`. The expected app logs are as follows:
41+
42+
```text
43+
== APP - chaining == Activity1: Received input: This.
44+
== APP - chaining == Activity2: Received input: This is.
45+
== APP - chaining == Activity3: Received input: This is task.
46+
```
47+
48+
5. Use the GET request in the [`chaining.http`](./chaining.http) file to get the status of the workflow, or use this cURL command:
49+
50+
```bash
51+
curl --request GET --url http://localhost:<DAPR_PORT>/v1.0/workflows/dapr/<INSTANCEID>
52+
```
53+
54+
Where `<INSTANCEID>` is the workflow instance ID you received in the `Location` header in the previous step.
55+
Where `<DAPR_PORT>` can be obtained by looking at the port mappings created by Testcontainers when running the application.
56+
You can find this by running `docker ps` and looking at the port-mappings
57+
```bash
58+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
59+
bc19a46794e1 daprio/daprd:1.15.4 "./daprd --app-id wo…" 48 seconds ago Up 48 seconds 0.0.0.0:61693->3500/tcp, 0.0.0.0:61694->50001/tcp
60+
```
61+
For this example: `61693` which was mapped to the Dapr port `3500` (`0.0.0.0:61693->3500/tcp`).
62+
6. The expected serialized output of the workflow is:
63+
64+
```txt
65+
"\"This is task chaining\""
66+
```
67+
68+
6. Stop the application by pressing `Ctrl+C`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@apphost=http://localhost:5255
2+
3+
### Start the TaskChaining workflow
4+
# @name startWorkflowRequest
5+
POST {{ apphost }}/start
6+
7+
8+
@instanceId={{startWorkflowRequest.response.headers.Location}}
9+
@daprHost=http://localhost:3555
10+
### Get the workflow status
11+
GET {{ daprHost }}/v1.0/workflows/dapr/{{ instanceId }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>3.4.5</version>
10+
<relativePath/> <!-- lookup parent from repository -->
11+
</parent>
12+
13+
<artifactId>task-chaining</artifactId>
14+
<name>task-chaining</name>
15+
<description>Task Chaining Workflow Example</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-actuator</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-test</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>io.dapr.spring</groupId>
32+
<artifactId>dapr-spring-boot-starter</artifactId>
33+
<version>0.15.0-rc-5</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>io.dapr.spring</groupId>
37+
<artifactId>dapr-spring-boot-starter-test</artifactId>
38+
<version>0.15.0-rc-5</version>
39+
<scope>test</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.rest-assured</groupId>
43+
<artifactId>rest-assured</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples;
15+
16+
import org.springframework.boot.SpringApplication;
17+
import org.springframework.boot.autoconfigure.SpringBootApplication;
18+
19+
20+
@SpringBootApplication
21+
public class TaskChainingApplication {
22+
23+
public static void main(String[] args) {
24+
SpringApplication.run(TaskChainingApplication.class, args);
25+
}
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples;
15+
16+
import com.fasterxml.jackson.databind.ObjectMapper;
17+
import org.springframework.boot.web.client.RestTemplateBuilder;
18+
import org.springframework.context.annotation.Bean;
19+
import org.springframework.context.annotation.Configuration;
20+
import org.springframework.web.client.RestTemplate;
21+
22+
@Configuration
23+
public class TaskChainingConfiguration {
24+
25+
@Bean
26+
public RestTemplate restTemplate() {
27+
return new RestTemplateBuilder().build();
28+
}
29+
30+
@Bean
31+
public ObjectMapper mapper() {
32+
return new ObjectMapper();
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples;
15+
16+
17+
import io.dapr.spring.workflows.config.EnableDaprWorkflows;
18+
import io.dapr.springboot.examples.chain.ChainWorkflow;
19+
import io.dapr.workflows.client.DaprWorkflowClient;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.web.bind.annotation.PostMapping;
24+
import org.springframework.web.bind.annotation.RestController;
25+
26+
import java.util.concurrent.TimeoutException;
27+
28+
@RestController
29+
@EnableDaprWorkflows
30+
public class TaskChainingRestController {
31+
32+
private final Logger logger = LoggerFactory.getLogger(TaskChainingRestController.class);
33+
34+
@Autowired
35+
private DaprWorkflowClient daprWorkflowClient;
36+
37+
38+
/**
39+
* Run Chain Demo Workflow
40+
* @return the output of the ChainWorkflow execution
41+
*/
42+
@PostMapping("start")
43+
public String chain() throws TimeoutException {
44+
String instanceId = daprWorkflowClient.scheduleNewWorkflow(ChainWorkflow.class, "This");
45+
return instanceId;
46+
}
47+
48+
49+
50+
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples.chain;
15+
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class Activity1 implements WorkflowActivity {
24+
25+
@Override
26+
public Object run(WorkflowActivityContext ctx) {
27+
Logger logger = LoggerFactory.getLogger(Activity1.class);
28+
var input = ctx.getInput(String.class);
29+
logger.info(ctx.getName() + " : Received input: " + input);
30+
return input + " is";
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples.chain;
15+
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class Activity2 implements WorkflowActivity {
24+
25+
@Override
26+
public Object run(WorkflowActivityContext ctx) {
27+
Logger logger = LoggerFactory.getLogger(Activity2.class);
28+
var input = ctx.getInput(String.class);
29+
logger.info(ctx.getName() + " : Received input: " + input);
30+
return input + " task";
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples.chain;
15+
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
import org.springframework.stereotype.Component;
21+
22+
@Component
23+
public class Activity3 implements WorkflowActivity {
24+
25+
@Override
26+
public Object run(WorkflowActivityContext ctx) {
27+
Logger logger = LoggerFactory.getLogger(Activity3.class);
28+
var input = ctx.getInput(String.class);
29+
logger.info(ctx.getName() + " : Received input: " + input);
30+
return input + " chaining";
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.springboot.examples.chain;
15+
16+
import io.dapr.workflows.Workflow;
17+
import io.dapr.workflows.WorkflowStub;
18+
import org.springframework.stereotype.Component;
19+
20+
@Component
21+
public class ChainWorkflow implements Workflow {
22+
@Override
23+
public WorkflowStub create() {
24+
return ctx -> {
25+
ctx.getLogger().info("Starting Workflow: " + ctx.getName());
26+
27+
var input = ctx.getInput(String.class);
28+
String result = ctx.callActivity(Activity1.class.getName(), input, String.class).await();
29+
result = ctx.callActivity(Activity2.class.getName(), result, String.class).await();
30+
result = ctx.callActivity(Activity3.class.getName(), result, String.class).await();
31+
32+
ctx.complete(result);
33+
};
34+
}
35+
}

0 commit comments

Comments
 (0)