Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src
manifest.yml
pom.xml
readme.md

readme.md

Embed Camunda into your Spring Boot application

You can use Camunda as a library within your own Spring Boot application by leveraging the Camunda Spring Boot Starter.

This is one of multiple possible approaches.

Screencast

This video walks you through the whole procedure:

Screencast

Step-by-step

  1. Add a normal Spring REST controller to provide your custom REST API to say hello.

  2. Add a Maven dependency (see pom.xml) for Camunda. There is one for the core engine, one for the REST API and one for web tools like Cockpit (make sure you also have a data source available, I use H2 for the simple example).

<dependency> <!-- Headless engine -->
  <groupId>org.camunda.bpm.springboot</groupId>
  <artifactId>camunda-bpm-spring-boot-starter</artifactId>
</dependency>
<dependency> <!-- REST API, contains headless engine -->
  <groupId>org.camunda.bpm.springboot</groupId>
  <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
</dependency>
<dependency> <!-- Web tools, contains headless engine -->
  <groupId>org.camunda.bpm.springboot</groupId>
  <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
</dependency>
  1. Use @EnableProcessApplication and add a META-INF/processes.xml file. While this is optional, it is the recommended way of doing it with some advantages.

  2. Add the BPMN workflow to src/main/resources.

  3. Implement a Spring bean to express the logic of the "Sysout" service task.

Please refer to the sample application available on GitHub for all the details.

The Spring Boot application includes a proper JUnit test cases (using an in-memory H2 database) and can be started locally (using a file based H2 database).

Now you can push this application to PCF:

  • Add a service for a relational database named camunda-db. I used ElephantDB as managed service offering of PostgreSQL. But any database supported for Camunda will do.
  • Install PCF CLI locally.
  • Login (use api.run.pivotal.io as API endpoint if you run on PCF in the cloud):
cf login
  • Build and push the application. Check the PCF manifest file to make sure that it references the right database service.
mvn clean install && cf push -p target/*.jar

Hint: In on-prem installations of PCF the java buildpack might not yet be available, then you need to specify that in your command:

cf push -p target/*.jar https://github.com/cloudfoundry/java-buildpack.git

No you can trigger your own REST API with a client of your choice (e.g. Postman, ARC or CURL):

curl --request POST -F 'text=some text shown later' http://camunda-pcf-spring-boot-embedded-engine-sample.cfapps.io/hello

You can also use the Camunda REST API to access the engine, e.g. to query completed process instances:

curl http://camunda-pcf-spring-boot-embedded-engine-sample.cfapps.io/rest/history/process-instance?completed=true

Possible extensions

Using an external database

You might not leverage a PCF service to provide the database. In this case you have to

  • Configure your database properties in the cloud profile, e.g. by copying spring.datasource.url and related datasource parameters in a file application-cloud.properties, e.g.
spring.datasource.url= # JDBC URL of the database.
spring.datasource.username= # Login username of the database.
spring.datasource.password= # Login password of the database.
  • Make sure you disable the 'DataSourceCloudConfiguration', the easiest way is to delete the DataSourceCloudConfiguration.java file completly.

Further reading

A more sophisticated example using AMQP can be found here: https://github.com/berndruecker/camunda-spring-boot-amqp-microservice-cloud-example.

You can’t perform that action at this time.