docs/content/stable/integrations/camunda.md
Camunda is a Java-based framework supporting BPMN (Business Process Modeling Notation) for workflow and process automation, CMMN (Case Management Model and Notation) for Case Management and DMN (Decision Model and Notation) for business decision management.
Camunda supports PostgreSQL as a datasource. Because YugabyteDB is wire compatible with PostgreSQL, it works out of the box with Camunda as a datasource. This document covers how to:
This tutorial assumes that:
Locate the spring.datasource section in the following files:
camunda-bpm-run-7.17.0/configuration/default.ymlcamunda-bpm-run-7.17.0/configuration/production.ymlModify the spring.datasource section that uses standard PostgreSQL JDBC driver. Change the url value to point to the YugabyteDB cluster you started:
# datasource configuration is required
spring.datasource:
url: jdbc:postgresql://localhost:5433/yugabyte
driver-class-name: org.postgresql.Driver
username: yugabyte
password: yugabyte
Download the PostgreSQL JDBC driver JAR fileand place it in the camunda-bpm-run-7.17.0/configuration/userlib directory. Alternatively, you can also use the YugabyteDB JDBC driver to connect Camunda to a YugabyteDB cluster. To do so, modify the spring.datasource section in each file to point to the YugabyteDB cluster you started, and replace the value of driver-class-name with com.yugabyte.Driver.
# datasource configuration is required
spring.datasource:
url: jdbc:yugabytedb://localhost:5433/yugabyte
driver-class-name: com.yugabyte.Driver
username: yugabyte
password: yugabyte
Then, download the YugabyteDB JDBC driver [JAR file](https://repo1.maven.org/maven2/com/yugabyte/jdbc-yugabytedb/{{< version-driver-java >}}/jdbc-yugabytedb-{{< version-driver-java >}}.jar) and place it in the camunda-bpm-run-7.17.0/configuration/userlib directory. Read more about the YugabyteDB JDBC driver.
Start the Camunda Platform server using ./start.sh on Linux or macOS, or ./start.bat on Windows.
After the server is started, you'll be able to see a few tables getting created in the database. To verify, do the following:
./bin/ysqsh.\d to see the list of tables.ACT_ are created.See the Camunda docs for more details regarding the tables created.
In this example, taken from the Camunda quick-start, you'll use Camunda Modeler to design and deploy a small BPMN for charging the cards.
You'll need three events:
Note that for the service event, you need an external task worker. For that purpose, you'll use Node.js.
payment-retrieval in the ID property field to configure an ID for the process. The process engine uses the property ID as an identifier for the executable process; it's good practice to set it to a human-readable name.After modeling the process, you can create some business logic. Camunda Platform is built so that you can implement your business logic in different languages. You have the choice which language suits your project best. For this example, you'll use JavaScript (Node.js).
Create a new Node.js project:
mkdir charge-card-worker
cd ./charge-card-worker
npm init -y
Add the Camunda External Task Client library to your project:
npm install camunda-external-task-client-js
npm install -D open
Next, you'll create a new ExternalTaskClient that subscribes to the charge-card topic.
When the process engine encounters a service task configured to be externally handled, it creates an external task instance on which your handler reacts. The handler in this example uses long polling in the ExternalTaskClient to make the communication more efficient.
Create a new file called worker.js with the following contents:
const { Client, logger } = require('camunda-external-task-client-js');
const open = require('open');
// configuration for the Client:
// - 'baseUrl': URL to the Process Engine
// - 'logger': utility to automatically log important events
// - 'asyncResponseTimeout': long polling timeout (then a new request will be issued)
const config = {
baseUrl: 'http://localhost:8080/engine-rest',
use: logger,
asyncResponseTimeout: 10000
};
// create a Client instance with custom configuration
const client = new Client(config);
// susbscribe to the topic: 'charge-card'
client.subscribe('charge-card', async function({ task, taskService }) {
// Put your business logic here
// Get a process variable
const amount = task.variables.get('amount');
const item = task.variables.get('item');
console.log(`Charging credit card with an amount of ${amount}€ for the item '${item}'...`);
// Complete the task
await taskService.complete(task);
});
Run the Node.js script you just created:
node ./worker.js
To deploy the process, do the following:
Click the deploy button in Camunda Modeler, enter the deployment name "Payment Retrieval", and click the Deploy button.
If you're running Camunda Modeler version 3.0.0 or later, you need to provide the URL of an Endpoint Configuration along with the deployment details. This can be either the root endpoint to the REST API (such as http://localhost:8080/engine-rest) or an exact endpoint to the deployment creation method (such as http://localhost:8080/engine-rest/deployment/create).
Use Cockpit to verify the deployment.
Navigate to http://localhost:8080/camunda/app/cockpit/ and log in with a username and password of demo. Your process called Payment Retrieval should be visible on the dashboard.
Use the Camunda REST API to start a new process instance by sending a POST request:
curl -H "Content-Type: application/json" \
-X POST \
-d '{"variables": {"amount": {"value":555,"type":"integer"}, "item": {"value":"item-xyz"} } }' \
http://localhost:8080/engine-rest/process-definition/key/payment-retrieval/start
You can also make a POST request from another tool, such as Postman, with the following JSON body:
{
"variables": {
"amount": {
"value":555,
"type":"integer"
},
"item": {
"value": "item-xyz"
}
}
}
In your worker, you should now see the output in your console. You have successfully started and executed your first small process.