Skip to content

Commit 02a8478

Browse files
authored
Merge pull request #523 from fjtirado/Fix_#520
[Fix #520] Updating readme
2 parents 03435c0 + 8f4ec43 commit 02a8478

File tree

22 files changed

+534
-48
lines changed

22 files changed

+534
-48
lines changed

README.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Provides the Java API for the [Serverless Workflow Specification](https://github
88
With the SDK you can:
99

1010
* Read workflow JSON and YAML definitions
11-
* Write workflow in JSON and YAML format.
11+
* Write workflow definitions in JSON and YAML formats.
12+
* Test your workflow definitions using the reference implementation.
1213

13-
Serverless Workflow Java SDK is **not** a workflow runtime implementation but can be used by Java runtime implementations to parse workflow definitions.
1414

15-
### Status
15+
## Status
1616

1717
| Latest Releases | Conformance to spec version |
1818
| :---: | :---: |
@@ -25,17 +25,18 @@ Serverless Workflow Java SDK is **not** a workflow runtime implementation but ca
2525

2626
Note that 6.0.0.Final, which will be the one for specification version 0.9, is skipped intentionally in case someone want to work on it.
2727

28-
### JDK Version
28+
## JDK Version
2929

3030
| SDK Version | JDK Version |
3131
| :---: | :---: |
32+
| 7.0.0 and after | 17 |
3233
| 5.0.0 and after | 11 |
3334
| 4.0.x and before | 8 |
3435

35-
### Getting Started
36+
## Getting Started
3637

3738

38-
#### Building SNAPSHOT locally
39+
### Building SNAPSHOT locally
3940

4041
To build project and run tests locally:
4142

@@ -47,7 +48,7 @@ mvn clean install
4748
The project uses [Google's code styleguide](https://google.github.io/styleguide/javaguide.html).
4849
Your changes should be automatically formatted during the build.
4950

50-
#### Maven projects:
51+
### Maven projects:
5152

5253
Add the following dependencies to your pom.xml `dependencies` section:
5354

@@ -59,19 +60,28 @@ Add the following dependencies to your pom.xml `dependencies` section:
5960
</dependency>
6061
```
6162

62-
#### Gradle projects:
63+
### Gradle projects:
6364

6465
Add the following dependencies to your build.gradle `dependencies` section:
6566

6667
```text
6768
implementation("io.serverlessworkflow:serverlessworkflow-api:7.0.0-SNAPSHOT")
6869
```
6970

70-
### How to Use
71+
## How to Use
7172

72-
#### Creating from JSON/YAML source
73+
There are, roughly speaking, two kind of users of this SDK:
74+
* Those ones interested on implementing their own runtime using Java.
75+
* Those ones interested on using the provided runtime reference implementation.
7376

74-
You can create a Workflow instance from JSON/YAML source:
77+
### Implementing your own runtime
78+
79+
For those ones interested on implementing their own runtime, this SDK provides an easy way to load an in memory representation of a given workflow definition.
80+
This in-memory representation consists of a hierarchy of POJOS directly generated from the Serverless Workflow specification [schema](api/src/main/resources/schema/workflow.yaml), which ensures the internal representation is aligned with the specification schema. The root of the hierarchy is `io.serverlessworkflow.api.types.Workflow` class
81+
82+
### Reading workflow definition from JSON/YAML source
83+
84+
You can read a Workflow definition from JSON/YAML source:
7585

7686
Let's say you have a simple YAML based workflow definition in a file name `simple.yaml` located in your working dir:
7787

@@ -93,7 +103,7 @@ do:
93103

94104
```
95105

96-
To parse it and create a Workflow instance you can do:
106+
To parse it and get a Workflow instance you can do:
97107

98108
``` java
99109

@@ -102,15 +112,31 @@ try (InputStream in = new FileInputStream("simple.yaml")) {
102112
// Once you have the Workflow instance you can use its API to inspect it
103113
}
104114
```
115+
By default, Workflows are not validated against the schema (performance being the priority). If you want to enable validation, you can do that by using:
116+
117+
``` java
118+
try (InputStream in = new FileInputStream("simple.yaml")) {
119+
Workflow workflow = WorkflowReader.validation().readWorkflow (in, WorkflowFormat.YAML);
120+
// Once you have the Workflow instance you can use its API to inspect it
121+
}
122+
```
105123

106-
#### Writing a workflow
124+
For additional reading helper methods, including the one to read a workflow definition from classpath, check [WorkflowReader](api/src/main/java/io/serverlessworkflow/api/WorkflowReader.java) class.
107125

108-
Given a workflow definition, you can store it using JSON or YAML format.
126+
### Writing workflow definition to a JSON/YAML target
127+
128+
Given a Workflow instance, you can store it using JSON or YAML format.
109129
For example, to store a workflow using json format in a file called `simple.json`, you write
110130

111131
``` java
112132
try (OutputStream out = new FileOutputStream("simple.json")) {
113133
WorkflowWriter.writeWorkflow(out, workflow, WorkflowFormat.JSON);
114134
}
115135

116-
```
136+
```
137+
For additional writing helper methods, check [WorkflowWriter](api/src/main/java/io/serverlessworkflow/api/WorkflowWriter.java) class.
138+
139+
### Reference implementation
140+
141+
The reference implementation provides a ready-to-use runtime that supports the Serverless Workflow Specification. It includes a workflow execution engine, validation utilities, and illustrative examples to help you quickly test and deploy your workflows. For details on usage, configuration, and supported features, see [readme](impl/README.md).
142+

examples/events/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>io.serverlessworkflow</groupId>
5+
<artifactId>serverlessworkflow-examples</artifactId>
6+
<version>7.0.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>events</artifactId>
9+
<dependencies>
10+
<dependency>
11+
<groupId>io.serverlessworkflow</groupId>
12+
<artifactId>serverlessworkflow-impl-core</artifactId>
13+
</dependency>
14+
<dependency>
15+
<groupId>org.slf4j</groupId>
16+
<artifactId>slf4j-simple</artifactId>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package events;
17+
18+
import io.serverlessworkflow.api.WorkflowReader;
19+
import io.serverlessworkflow.impl.WorkflowApplication;
20+
import io.serverlessworkflow.impl.WorkflowDefinition;
21+
import io.serverlessworkflow.impl.WorkflowInstance;
22+
import java.io.IOException;
23+
import java.util.Map;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
public class EventExample {
28+
29+
private static final Logger logger = LoggerFactory.getLogger(EventExample.class);
30+
31+
public static void main(String[] args) throws IOException {
32+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
33+
WorkflowDefinition listenDefinition =
34+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("listen.yaml"));
35+
WorkflowDefinition emitDefinition =
36+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("emit.yaml"));
37+
WorkflowInstance waitingInstance = listenDefinition.instance(Map.of());
38+
waitingInstance
39+
.start()
40+
.thenAccept(node -> logger.info("Waiting instance completed with result {}", node));
41+
logger.info("Listen instance waiting for proper event, Status {}", waitingInstance.status());
42+
logger.info("Publishing event with temperature 35");
43+
emitDefinition.instance(Map.of("temperature", 35)).start().join();
44+
logger.info(
45+
"Listen instance still waiting for proper event, Status {}", waitingInstance.status());
46+
logger.info("Publishing event with temperature 39");
47+
emitDefinition.instance(Map.of("temperature", 39)).start().join();
48+
}
49+
}
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: test
4+
name: emit
5+
version: '0.1.0'
6+
do:
7+
- emitEvent:
8+
emit:
9+
event:
10+
with:
11+
source: https://hospital.com
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data:
14+
temperature: ${.temperature}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: listen
5+
version: '0.1.0'
6+
do:
7+
- callDoctor:
8+
listen:
9+
to:
10+
one:
11+
with:
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data: ${ .temperature > 38 }

examples/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>io.serverlessworkflow</groupId>
5+
<artifactId>serverlessworkflow-parent</artifactId>
6+
<version>7.0.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>serverlessworkflow-examples</artifactId>
9+
<packaging>pom</packaging>
10+
<dependencyManagement>
11+
<dependencies>
12+
<dependency>
13+
<groupId>io.serverlessworkflow</groupId>
14+
<artifactId>serverlessworkflow-impl-core</artifactId>
15+
<version>${project.version}</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>io.serverlessworkflow</groupId>
19+
<artifactId>serverlessworkflow-impl-http</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.slf4j</groupId>
24+
<artifactId>slf4j-simple</artifactId>
25+
<version>2.0.16</version>
26+
</dependency>
27+
</dependencies>
28+
</dependencyManagement>
29+
<modules>
30+
<module>simpleGet</module>
31+
<module>events</module>
32+
</modules>
33+
</project>

impl/bom/pom.xml renamed to examples/simpleGet/pom.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
<modelVersion>4.0.0</modelVersion>
33
<parent>
44
<groupId>io.serverlessworkflow</groupId>
5-
<artifactId>serverlessworkflow-impl</artifactId>
5+
<artifactId>serverlessworkflow-examples</artifactId>
66
<version>7.0.0-SNAPSHOT</version>
77
</parent>
8-
<artifactId>serverlessworkflow-impl-bom</artifactId>
9-
<packaging>pom</packaging>
8+
<artifactId>simpleGet</artifactId>
109
<dependencies>
1110
<dependency>
1211
<groupId>io.serverlessworkflow</groupId>
@@ -16,5 +15,9 @@
1615
<groupId>io.serverlessworkflow</groupId>
1716
<artifactId>serverlessworkflow-impl-http</artifactId>
1817
</dependency>
18+
<dependency>
19+
<groupId>org.slf4j</groupId>
20+
<artifactId>slf4j-simple</artifactId>
21+
</dependency>
1922
</dependencies>
2023
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import io.serverlessworkflow.api.WorkflowReader;
19+
import java.io.IOException;
20+
import java.util.Map;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
public class BlockingExample {
25+
26+
private static final Logger logger = LoggerFactory.getLogger(BlockingExample.class);
27+
28+
public static void main(String[] args) throws IOException {
29+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
30+
logger.info(
31+
"Workflow output is {}",
32+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("get.yaml"))
33+
.instance(Map.of("petId", 10))
34+
.start()
35+
.join());
36+
}
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import io.serverlessworkflow.api.WorkflowReader;
19+
import java.io.IOException;
20+
import java.util.Map;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
public class NotBlockingExample {
25+
26+
private static final Logger logger = LoggerFactory.getLogger(NotBlockingExample.class);
27+
28+
public static void main(String[] args) throws IOException {
29+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
30+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("get.yaml"))
31+
.instance(Map.of("petId", 10))
32+
.start()
33+
.thenAccept(node -> logger.info("Workflow output is {}", node));
34+
logger.info("The request has been sent, this thread might continue doing stuff");
35+
}
36+
}
37+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: call-http-shorthand-endpoint
5+
version: '0.1.0'
6+
do:
7+
- getPet:
8+
call: http
9+
with:
10+
method: get
11+
endpoint: https://petstore.swagger.io/v2/pet/{petId}

0 commit comments

Comments
 (0)