jworkflow.mongodb

MongoDB Provider for JWorkflow

License

License

Categories

Categories

IDE Development Tools MongoDB Data Databases Net
GroupId

GroupId

net.jworkflow
ArtifactId

ArtifactId

jworkflow.providers.mongodb
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

jworkflow.mongodb
MongoDB Provider for JWorkflow
Project URL

Project URL

http://github.com/danielgerlag/jworkflow
Source Code Management

Source Code Management

http://github.com/danielgerlag/jworkflow/tree/master

Download jworkflow.providers.mongodb

How to add to project

<!-- https://jarcasting.com/artifacts/net.jworkflow/jworkflow.providers.mongodb/ -->
<dependency>
    <groupId>net.jworkflow</groupId>
    <artifactId>jworkflow.providers.mongodb</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.jworkflow/jworkflow.providers.mongodb/
implementation 'net.jworkflow:jworkflow.providers.mongodb:1.0'
// https://jarcasting.com/artifacts/net.jworkflow/jworkflow.providers.mongodb/
implementation ("net.jworkflow:jworkflow.providers.mongodb:1.0")
'net.jworkflow:jworkflow.providers.mongodb:jar:1.0'
<dependency org="net.jworkflow" name="jworkflow.providers.mongodb" rev="1.0">
  <artifact name="jworkflow.providers.mongodb" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.jworkflow', module='jworkflow.providers.mongodb', version='1.0')
)
libraryDependencies += "net.jworkflow" % "jworkflow.providers.mongodb" % "1.0"
[net.jworkflow/jworkflow.providers.mongodb "1.0"]

Dependencies

compile (5)

Group / Artifact Type Version
net.jworkflow : jworkflow jar 1.0
org.mongodb : mongodb-driver jar 3.9.1
org.springframework.data : spring-data-mongodb jar 1.10.17.RELEASE
org.springframework : spring-core jar 4.3.21.RELEASE
org.springframework : spring-context jar 4.3.21.RELEASE

Project Modules

There are no modules declared in this project.

JWorkflow

JWorkflow is a light weight workflow library for Java. It supports pluggable persistence and concurrency providers to allow for multi-node clusters.

Installing

Using Maven

Add jworkflow to your POM file as a dependency.

<dependencies>
    <dependency>
        <groupId>net.jworkflow</groupId>
        <artifactId>jworkflow</artifactId>
        <version>0.5-SNAPSHOT</version>
    </dependency>
</dependencies>

Using Gradle

dependencies { 
    compile 'net.jworkflow:jworkflow:0.5-SNAPSHOT'
}

Documentation

See Tutorial here.

Fluent API

Define your workflows with the fluent API.

public class HelloWorkflow implements Workflow {
   @Override
    public void build(WorkflowBuilder builder) {
        
        builder
            .startsWith(Task1.class)
            .then(Task2.class)                
            .then(Task3.class);        
    }    
}
...
...
public class Task1 implements StepBody {

    @Override
    public ExecutionResult run(StepExecutionContext context) {
        System.out.println("Hello world");
        return ExecutionResult.next();
    }    
}

JSON Workflow Definitions

Define your workflows in JSON

{
  "id": "HelloWorld",
  "version": 1,
  "steps": [
    {
      "id": "hello",
      "stepType": "com.myapp.Step1",
      "nextStepId": "bye"
    },        
    {
      "id": "bye",
      "stepType": "com.myapp.Step2"
    }
  ]
}

Sample use cases

  • New user workflow
public class MyData {    
    public String email;
    public String password;
    public String userId;
}


public class MyWorkflow implements Workflow<MyData> {

    ...

    @Override
    public void build(WorkflowBuilder<MyData> builder) {
        builder
            .startsWith(CreateUser.class)  
                .input((step, data) -> step.email = data.email)
                .input((step, data) -> step.password = data.password)
                .output((step, data) -> data.userId = step.userId)
            .then(SendConfirmationEmail.class)
                .waitFor("confirmation", data -> data.userId)
            .then(UpdateUser.class)
                .input((step, data) -> step.userId = data.userId);
    }    
}
  • Saga Transactions
public class MyWorkflow implements Workflow<MyData> {

    ...

    @Override
    public void build(WorkflowBuilder<MyData> builder) {
        builder
            .startsWith(CreateCustomer.class)  
            .then(PushToSalesforce.class)
                .onError(ErrorBehavior.RETRY)
            .then(PushToERP.class)
                .onError(ErrorBehavior.RETRY, Duration.ofMinutes(30));
    }    
}
builder
    .startsWith(LogStart.class)  
    .saga(saga -> saga
        .startsWith(Task1.class)
            .compensateWith(UndoTask1.class)
        .then(Task2.Class)
            .compensateWith(UndoTask2.class)
        .then(Task3.Class)
            .compensateWith(UndoTask3.class)
    )
    .onError(ErrorBehavior.RETRY, Duration.ofMinutes(30));
    .then(LogEnd.class);

Persistence

Since workflows are typically long running processes, they will need to be persisted to storage between steps. There are several persistence providers available as seperate packages.

  • Memory Persistence Provider (Default provider, for demo and testing purposes)
  • MongoDB
  • Amazon DynamoDB
  • (more to come soon...)

Multi-node clusters

By default, the WorkflowHost service will run as a single node using the built-in queue and locking providers for a single node configuration. Should you wish to run a multi-node cluster, you will need to configure an external queueing mechanism and a distributed lock manager to co-ordinate the cluster. These are the providers that are currently available.

Queue Providers

Distributed lock managers

Samples

Hello World

Passing Data

If condition

Responding to external events

Parallel ForEach

While loop

Saga Transactions

JSON Workflows

Contributors

  • Daniel Gerlag - Initial work

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Versions

Version
1.0
0.3
0.2
0.1