forked from serverlessworkflow/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix serverlessworkflow#520] Updating readme
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
- Loading branch information
Showing
10 changed files
with
293 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
examples/src/main/java/io/serverlessworkflow/impl/BlockingExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2020-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.serverlessworkflow.impl; | ||
|
||
import io.serverlessworkflow.api.WorkflowReader; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class BlockingExample { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(BlockingExample.class); | ||
|
||
public static void main(String[] args) throws IOException { | ||
try (WorkflowApplication appl = WorkflowApplication.builder().build()) { | ||
logger.info( | ||
"Workflow output is {}", | ||
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml")) | ||
.instance(Map.of("petId", 10)) | ||
.start() | ||
.join()); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
examples/src/main/java/io/serverlessworkflow/impl/NotBlockingExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2020-Present The Serverless Workflow Specification Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.serverlessworkflow.impl; | ||
|
||
import io.serverlessworkflow.api.WorkflowReader; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class NotBlockingExample { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(NotBlockingExample.class); | ||
|
||
public static void main(String[] args) throws IOException { | ||
try (WorkflowApplication appl = WorkflowApplication.builder().build()) { | ||
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml")) | ||
.instance(Map.of("petId", 10)) | ||
.start() | ||
.thenAccept(node -> logger.info("Workflow output is {}", node)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
document: | ||
dsl: '1.0.0-alpha5' | ||
namespace: examples | ||
name: call-http-shorthand-endpoint | ||
version: '0.1.0' | ||
do: | ||
- getPet: | ||
call: http | ||
with: | ||
method: get | ||
endpoint: https://petstore.swagger.io/v2/pet/{petId} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
 | ||
 [](https://gitpod.io/#https://github.com/serverlessworkflow/sdk-java) | ||
|
||
# Serverless Workflow Specification - Java SDK- Reference Implementation | ||
|
||
Welcome to Java SDK runtime reference implementation, a lightweight implementation of the Serverless Workflow specification which provides a simple, non blocking, reactive API for workflow execution. | ||
|
||
Although initially conceived mainly for testing purposes, it was designed to be easily expanded, so it can eventually become production ready. | ||
|
||
## Status. | ||
|
||
This reference implementation is currently capable of running workflows consisting of: | ||
|
||
|
||
* Switch | ||
* Set | ||
* Do | ||
* Raise | ||
* Listen | ||
* Emit | ||
* Fork | ||
* For | ||
* Try | ||
* Wait | ||
* Call | ||
* HTTP | ||
* Input and output schema validation. | ||
* Input, output and export filters. | ||
* Runtime expression special keyword | ||
* Error definitions | ||
|
||
|
||
## Setup | ||
|
||
### JDK Version | ||
|
||
Reference implementation requires [Java 17](https://openjdk.org/projects/jdk/17/) or newer versions. | ||
|
||
### Maven projects: | ||
|
||
Add the following dependencies to your pom.xml `dependencies` section: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>io.serverlessworkflow</groupId> | ||
<artifactId>serverlessworkflow-impl-core</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.serverlessworkflow</groupId> | ||
<artifactId>serverlessworkflow-impl-http</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
``` | ||
|
||
### Gradle projects: | ||
|
||
Add the following dependencies to your build.gradle `dependencies` section: | ||
|
||
```text | ||
implementation("io.serverlessworkflow:serverlessworkflow-impl-core:7.0.0-SNAPSHOT") | ||
implementation("io.serverlessworkflow:serverlessworkflow-impl-http:7.0.0-SNAPSHOT") | ||
``` | ||
|
||
## How to use | ||
|
||
This section is split in two. | ||
Quick version is intended for impatient users that want to try something as soon as possible. | ||
Detailed version is more suitable for those users interested on a more thoughtful discussion of the API | ||
Full code of the examples is available [here](/examples) | ||
|
||
### Quick version | ||
|
||
Assuming you have a workflow definition stored in a file called "do-single.yaml" available in your classpath | ||
|
||
```yaml | ||
document: | ||
dsl: '1.0.0-alpha5' | ||
namespace: examples | ||
name: call-http-shorthand-endpoint | ||
version: '0.1.0' | ||
do: | ||
- getPet: | ||
call: http | ||
with: | ||
method: get | ||
endpoint: https://petstore.swagger.io/v2/pet/{petId} | ||
``` | ||
In order to execute it, blocking the thread till the http request is completed, you should write | ||
``` java | ||
try (WorkflowApplication appl = WorkflowApplication.builder().build()) { | ||
logger.info( | ||
"Workflow output is {}", | ||
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml")) | ||
.instance(Map.of("petId", 10)) | ||
.start() | ||
.join()); | ||
} | ||
``` | ||
|
||
In order to execute it, without blocking the calling thread till the http request is completed, you should write | ||
|
||
``` java | ||
try (WorkflowApplication appl = WorkflowApplication.builder().build()) { | ||
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml")) | ||
.instance(Map.of("petId", 10)) | ||
.start() | ||
.thenAccept(node -> logger.info("Workflow output is {}", node)); | ||
} | ||
``` | ||
When the http request is done, both examples will print a similar output | ||
|
||
`Workflow output is {"id":10,"category":{"id":10,"name":"string"},"name":"doggie","photoUrls":["string"],"tags":[{"id":10,"name":"string"}],"status":"string"}` | ||
|
||
|
||
### Detailed version | ||
|
||
TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.