Getting started with CockroachDB and Flowable

Getting started with CockroachDB and Flowable

Last week, our friends at Flowable released Flowable 6.4.2, which officially adds support for CockroachDB. Flowable provides a workflow and Business Process Management (BPM) platform for developers, system admins and business users, and now integrates with CockroachDB in just a few steps, thanks to a recent collaboration. Cockroach Labs and Flowable engineers have been teaming up since the early stages of CockroachDB because it makes deploying Flowable that much easier. Plus, as they write in their blog

“What makes CockroachDB very interesting for Flowable is that it’s scalable and distributed database... In the world of processes and cases, atomicity is utmost importance, as data correctness is sacred.”

In their recent blog post about the integration, they show how to get started with running the Flowable engines on top of CockroachDB. We've replicated the steps below so you can get started: 

Step 1: Start CockroachDB

Download the CockroachDB binaries. Start it in a terminal by executing

./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: Create 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> 

This adds: 

    • The Flowable Spring Boot starter dependency. This will automatically create all Flowable engines (bpmn / cmmn / dmn) using the CockroachDB (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 3: Configure 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 4: Start 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: Run 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

...

Go ahead and query the database using any SQL tool to verify the data is in fact there. You’ll be able to validate that using CockroachDB with Flowable is exactly the same as running it against any other relational database.

 

 

Keep Reading

Automatic table statistics in CockroachDB

Last year, we rebuilt our cost-based optimizer from scratch for CockroachDB’s 2.1 release. …

Read more
How to do a one-step MySQL import in CockroachDB

Update 3/4/19: This feature is out of beta! Want to learn more? Check out our webinar on migrating MySQL data to …

Read more
Practical applications of JSON: Why and where you should use it

CockroachDB provides scale without sacrificing SQL functionality. It offers fully-distributed ACID …

Read more