Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mostafacs/quarkus-temporal-extension

Temporal workflow engine integration with quarkus
https://github.com/mostafacs/quarkus-temporal-extension

java quarkus temporal temporal-extension temporal-workflow temporal-workflows temporalio

Last synced: 4 months ago
JSON representation

Temporal workflow engine integration with quarkus

Awesome Lists containing this project

README

        

# QUARKUS - TEMPORAL EXTENSION

With this extension you can easily implement a temporal workflow in your quarkus project.
Review this [demo](https://github.com/mostafacs/quarkus-temporal-demo) for a quick start.
## How to use ?

1- Add extension dependency to your maven POM file.

* Quarkus 2.4.2 , JDK 11 and Native Image Build Support (graalvm-ce-java11-21.2.0)

```xml

com.sellware.quarkus-temporal
temporal-client
2.0.4

```

* Quarkus 1.x , JDK 8 ( Native image build not supported)

```xml

com.sellware.quarkus-temporal
temporal-client
1.13.1.7

```

2- Updated netty-shaded on quarkus-bom

```xml



io.quarkus
quarkus-bom
${quarkus.platform.version}
pom
import



io.grpc
grpc-netty-shaded
1.39.0

```

3- Add temporal server url config in `application.properties`

```properties
quarkus.temporal.service.url=localhost:7233
quarkus.temporal.multi-tenant.enabled=false # false is the default
```

Enable multi-tenancy will init RequestContext before calling the activity method.

4- Add configuration file named `workflow.yml` to resources folder

* Field `name` in annotation `@TemporalWorkflow` used to load workflow configurations
* Field `name` in annotation `@TemporalActivity` used to load activities configurations

#### Example

```yml
defaults:
workflowExecutionTimeout: 20 # in minutes default is 60 minute if not set
workflowRunTimeout: 15 # in minutes default is 60 minute
workflowTaskTimeout: 14 # in minutes default is 60 minute

activityScheduleToStartTimeout: 60 # in minutes default is 60 minute
activityScheduleToCloseTimeout: 60 # in minutes default is 60 minute
activityStartToCloseTimeout: 60 # in minutes default is 60 minute
#heartbeat timeout must be shorter than START_TO_CLOSE timeout
activityHeartBeatTimeout: 5 # in minutes default is 60 minute
activityRetryInitInterval: 1 # in minutes default is 5 minute
activityRetryMaxInterval: 1 # in minutes default is 1 minute if not set
activityRetryBackOffCoefficient: 1.0 # default is 1.0
activityRetryMaxAttempts: 5 # default is 1 attempt

# override defaults per workflow
workflows:
test:
executionTimeout: 2
runTimeout: 2
taskTimeout: 2
activities:
test:
scheduleTostartTimeout: 10
scheduleTocloseTimeout: 10
#startTocloseTimeout: 20
#heartbeatTimeout: 2
#retryInitInterval: 1
#retryMaxInterval: 1
#retryMaxAttempts: 1
```

### Declare your Temporal Activities:

```java
@ActivityInterface
public interface TestActivity {

String hello();
}
```

```java
// name used to get the activity configurations from workflow.yml
@TemporalActivity(name="test")
public class TestActivityImpl implements TestActivity {

// you can inject your services here.

@Override
public String hello() {
return "I'm hello activity";
}
}
```

### Declare your Temporal Workflows:

```java
@WorkflowInterface
public interface TestWorkflow {

@WorkflowMethod
void run();
}
```

```java
@TemporalWorkflow(queue = "testQueue", name="test")
public class TestWorkflowImpl implements TestWorkflow {

@TemporalActivityStub
TestActivity testActivity;

@Override
public void run() {
System.out.println(testActivity.hello());
Workflow.sleep(10000);
System.out.println("Workflow <<1>> completed");
}
}
```

### Add your own interceptors (you can add many interceptors classes)
```java
@Singleton
@Unremovable
public class TemporalLoggingInterceptor implements WorkerInterceptor {

@Override
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
return new MyWorkflowInboundInterceptor(next);
}

@Override
public ActivityInboundCallsInterceptor interceptActivity(ActivityInboundCallsInterceptor next) {
return new MyActivityInboundInterceptor(next);
}

}
```

### Run your workflow:

```java

@Path("/temporal-client")
@ApplicationScoped
public class TemporalClientController {

@Inject
WorkflowBuilder workflowBuilder;

@GET
public String hello() {
TestWorkflow testWorkflow = workflowBuilder.build(TestWorkflow.class, "test123");
WorkflowClient.execute(testWorkflow::run);
return "workfow started";
}
}

```