Flowable engineering blog post hero

Engineering

Getting Started with Flowable and CockroachDB

JULY 11, 2019

In Flowable 6.4.2, support for CockroachDB was added. We’ve sat together with the engineers from Cockroach Labs (the company behind CockroachDB) to make sure we’ve got the details right and to exchange feedback both ways.

After all, CockroachDB (called CRDB in next paragraphs) is not a ‘regular database’. According to it’s Github page, it’s a cloud-native SQL database for building global, scalable cloud services that survive disasters. It is a distributed SQL database built on a transactional and strongly-consistent key-value store. It scales horizontally; survives disk, machine, rack, and even datacenter failures with minimal latency disruption and no manual intervention.

What makes CRDB very interesting for Flowable is that it’s scalable and distributed database (simply add more nodes to the cluster to cope with more load or store data closer to where it is used) that is fully ACID transactional. In the world of processes and cases, atomicity is utmost importance, as data correctness is sacred.

Furthermore, it also means we can reuse all the existing code in the engines that’s been there for many years and which is battle-hardened by being used by many companies all over the world.

Let’s show how to get started with running the Flowable engines on top of CockroachDB. To make things a bit more interesting, let’s build a simple Spring Boot application that starts a process instance when a REST endpoint is hit.

(Note: obviously the CRDB integration also works in a non-Spring setup)

Step 1: Start CRDB

Download Cockroach from its website: https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html

In a terminal, to start it, execute

./cockroach start --insecure --host=localhost

Note that this is a simple (non-production) setup with only one node in insecure mode. See the docs for other ways of running it, including clustered.

We need a database and user to connect from our application. From the terminal, execute following commands which will create a flowable database and a flowable user.

./cockroach sql --insecure -e 'CREATE DATABASE flowable'./cockroach sql --insecure -e 'CREATE USER flowable'./cockroach sql --insecure -e 'GRANT ALL ON DATABASE flowable to flowable'

Step 2: Creating the project

Create a new Spring Boot application (e.g. by going to http://start.spring.io/ and generating an empty project) and add the following dependencies:

<dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-spring-boot-starter</artifactId>
    <version>6.4.2</version>
</dependency>
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.6</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

We’ve added

  • The Flowable Spring Boot starter dependency. This will automatically create all Flowable engines (bpmn / cmmn / dmn) using the CRDB datasource.

  • The PostgreSQL jdbc driver. CRDB is compatible with PostgreSQL (read about that in detail here), which makes it easy to reuse a plethora of tools out there.

  • The Spring Boot web starter that we need to craft the REST endpoint.

Step 2: Configuring the application

Flowable needs to know how to connect to the database. Add an application.properties file to the resources:

spring.datasource.url=jdbc:postgresql://127.0.0.1:26257/flowable?sslmode=disable**spring.datasource.username=flowable**spring.datasource.password=

Step 3: The application

The application is a simple Spring Boot application. It has a RestController that has one method that starts a process instance (the process definition is actually in the processes folder of the resources and it automatically picked up).

The ProcessEngine and its services are created automatically and configured to use the CRDB database. As shown in the example below, they are automatically injected in the controller:

@SpringBootApplication
public class
 Application {  

**public static void** main(String\[\] args) {  
    SpringApplication._run_(Application.**class**, args);  
}  

@RestController  
**class** MyRestController {  

    **private** RuntimeService **runtimeService**;  
    **private** TaskService **taskService**;  

    **public** MyRestController(**final** RuntimeService runtimeService, **final** TaskService taskService) {  
        **this**.**runtimeService** \= runtimeService;  
        **this**.**taskService** \= taskService;  
    }  

    @GetMapping(**"/start"**)  
    **public void** startProcessInstance() {  
        **runtimeService**.startProcessInstanceByKey(**"helloWorld"**);  

        System.**_out_**.println(**"Number of tasks created: "** \+ **taskService**.createTaskQuery().count());  
    }  

}  

}  

Step 4: Running it

After starting the application (from your IDE or terminal), the REST endpoint can now be called:

curl http://localhost:8080/start

which will output

Number of tasks created: 1
Number of tasks created: 2
Number of tasks created: 3
...

which proves it works (you can query the database using any SQL tool to verify the data is in fact there) and demonstrates that using CockroachDB with Flowable is exactly the same as running it against any other relational database.

Joram Barrez_MG 7807

Joram Barrez

Principal Software Architect

A core developer at Flowable with over a decade of experience in open source software and of building scalable process engines. He co-founded the Activiti project (on which Flowable is based) and was part of the JBoss jBPM team before that.

Share this Blog post
pexels-google-deepmind-18069697
Engineering | FEBRUARY 19, 2024
The Value of AI in Modeling

As AI gains prominence as a pivotal technology and enterprises increasingly seek to leverage its capabilities, we are actively exploring diverse avenues for integrating AI into process automation.

pixabay_egg-583163_1920_stevepb
Engineering | OCTOBER 3, 2023
Low-code, High Impact: Flowable & CMMN for Complex Use Cases

The key to managing complexity is to combine different and multiple tools leads to better, faster, and more maintainable solutions. For example, combining BPMN with CMMN.

AdobeStock_566576699
Engineering | OCTOBER 2, 2023
The New Flowable eLearning Platform

Discover the reasons behind our brand-new Flowable eLearning platform and explore its features by registering for our inaugural free course.