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.
This video walks you through the whole procedure:
Add a normal Spring REST controller to provide your custom REST API to say hello.
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>
Add the BPMN workflow to src/main/resources.
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):
- 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
- Now you can access your application by either triggering your REST endpoint or open up the Camunda web applications. PCF as default creates an URL that matches exactly your application name, in my example that is https://camunda-pcf-spring-boot-embedded-engine-sample.cfapps.io:
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:
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.urland related datasource parameters in a file
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
A more sophisticated example using AMQP can be found here: https://github.com/berndruecker/camunda-spring-boot-amqp-microservice-cloud-example.