Camunda
Since Camel 4.19
Both producer and consumer are supported
The Camunda component provides the ability to interact with Camunda 8 process orchestration clusters using the Camunda Java Client.
This component replaces the deprecated camel-zeebe component, which used the older Zeebe Java Client.
| Prerequisites You must have access to a Camunda 8 cluster. This can be:
|
To use the Camunda component, Maven users will need to add the following dependency to their pom.xml:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-camunda</artifactId>
<version>${camel-version}</version>
</dependency> Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Camunda component supports 10 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
gRPC address of the Camunda cluster (e.g. http://localhost:26500). Used for self-managed connections when clusterId is not set. | String | ||
REST address of the Camunda cluster (e.g. http://localhost:8080). Used for self-managed connections when clusterId is not set. | String | ||
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Client ID for OAuth / SaaS authentication. | String | ||
Client secret for OAuth / SaaS authentication. | String | ||
Camunda SaaS cluster ID. When set, the client connects via the cloud builder. | String | ||
OAuth authorization server URL for self-managed authentication. | String | ||
Camunda SaaS region (default: bru-2). | bru-2 | String |
Endpoint Options
The Camunda endpoint is configured using URI syntax:
camunda:operationName
With the following path and query parameters:
Query Parameters (7 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
Format the result in the body as JSON. | false | boolean | |
Job type for the job worker. | String | ||
Timeout for job worker in seconds. | 10 | int | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean |
Message Headers
The Camunda component supports 8 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | Job key for the worker job. | long | |
CamelCamundaResourceName (producer) Constant: | Resource name for deploy operation. | String | |
CamelCamundaIsSuccess (producer) Constant: | Indicates if the operation was successful. | boolean | |
CamelCamundaErrorMessage (producer) Constant: | Error message if operation failed. | String | |
CamelCamundaErrorCode (producer) Constant: | Error code if operation failed. | String | |
CamelCamundaBPMNProcessId (producer) Constant: | The process ID of a deployed process. | String | |
CamelCamundaVersion (producer) Constant: | The version of a deployed process. | int | |
CamelCamundaProcessDefinitionKey (producer) Constant: | The process definition key of a deployed process. | long |
Connection Modes
Camunda SaaS (Cloud)
Set the clusterId, clientId, clientSecret, and region component options.
CamundaComponent camunda = context.getComponent("camunda", CamundaComponent.class);
camunda.setClusterId("your-cluster-id");
camunda.setClientId("your-client-id");
camunda.setClientSecret("your-client-secret");
camunda.setRegion("bru-2"); Self-Managed
Set the grpcAddress and restAddress component options. For authenticated self-managed clusters, also set clientId, clientSecret, and oAuthAPI.
CamundaComponent camunda = context.getComponent("camunda", CamundaComponent.class);
camunda.setGrpcAddress("http://localhost:26500");
camunda.setRestAddress("http://localhost:8080"); Usage
Producer Endpoints
| Endpoint | Description |
|---|---|
| Creates and starts an instance of the specified process. |
| Cancels a running process instance. |
| Publishes a message. |
| Completes a job for a service task. |
| Fails a job. |
| Updates the number of retries for a job. |
| Throws an error to indicate that a business error has occurred. |
| Deploys a process resource. Currently supports process definitions. |
The endpoints accept either Java request objects as shown in the examples below or JSON. In JSON, camel case for property names is replaced with all lower case separated by underscores, e.g., processId becomes process_id.
Examples
-
startProcess
-
Java
-
YAML
-
XML
from("direct:start")
.process(exchange -> {
ProcessRequest request = new ProcessRequest();
request.setProcessId("processId");
request.setVariables(new HashMap<String,Object> ());
exchange.getIn().setBody(request);
})
.to("camunda://startProcess")
.process(exchange -> {
ProcessResponse body = exchange.getIn().getBody(ProcessResponse.class);
if (body != null) {
boolean success = body.isSuccess();
long processInstanceKey = body.getProcessInstanceKey();
}
}); - route:
from:
uri: direct:start-process
steps:
- marshal:
json: {}
- setBody:
simple: '{"process_id":"processId","variables":${body}}'
- to:
uri: "camunda://startProcess" <route>
<from uri="direct:start-process"/>
<marshal>
<json/>
</marshal>
<setBody>
<simple>{"process_id":"processId","variables":${body}}</simple>
</setBody>
<to uri="camunda://startProcess"/>
</route> JSON Request Example
{
"process_id" : "Process_0e3ldfm",
"variables" : { "v1": "a", "v2": 10 }
} JSON Response Example
{
"success": true,
"process_id": "Process_0e3ldfm",
"process_instance_key": 2251799813688297,
"process_version": 4,
"process_key": 2251799813685906
} -
cancelProcess
-
Java
-
YAML
-
XML
from("direct:cancel")
.process(exchange -> {
ProcessRequest request = new ProcessRequest();
request.setProcessInstanceKey(123);
exchange.getIn().setBody(request);
})
.to("camunda://cancelProcess"); - route:
from:
uri: direct:cancel
steps:
- setBody:
simple: '{"process_instance_key": 123}'
- to:
uri: "camunda://cancelProcess" <route>
<from uri="direct:cancel"/>
<setBody>
<simple>{"process_instance_key": 123}</simple>
</setBody>
<to uri="camunda://cancelProcess"/>
</route> -
publishMessage
-
Java
-
YAML
-
XML
from("direct:message")
.process(exchange -> {
MessageRequest request = new MessageRequest();
request.setCorrelationKey("messageKey");
request.setTimeToLive(100);
request.setVariables(new HashMap<String,Object>());
request.setName("MessageName");
exchange.getIn().setBody(request);
})
.to("camunda://publishMessage"); - route:
from:
uri: direct:message
steps:
- setBody:
simple: '{"name":"MessageName","correlation_key":"messageKey","time_to_live":100,"variables":{}}'
- to:
uri: "camunda://publishMessage" <route>
<from uri="direct:message"/>
<setBody>
<simple>{"name":"MessageName","correlation_key":"messageKey","time_to_live":100,"variables":{}}</simple>
</setBody>
<to uri="camunda://publishMessage"/>
</route> -
deployResource
-
Java
-
YAML
-
XML
from("direct:deploy")
.process(exchange -> {
exchange.getIn().setHeader(CamundaConstants.RESOURCE_NAME, "process.bpmn");
exchange.getIn().setBody(content.getBytes());
})
.to("camunda://deployResource"); - route:
from:
uri: direct:deploy
steps:
- setHeader:
name: CamelCamundaResourceName
simple: "process.bpmn"
- to:
uri: "camunda://deployResource" <route>
<from uri="direct:deploy"/>
<setHeader name="CamelCamundaResourceName">
<simple>process.bpmn</simple>
</setHeader>
<to uri="camunda://deployResource"/>
</route> Consumer Endpoints
| Endpoint | Description |
|---|---|
worker | Registers a job worker for a job type and provides messages for available jobs. |
camel-camunda creates a route exchange per job type with a job in the body. The CamelCamundaJobKey header is set automatically for each job.
Auto-Complete / Auto-Fail
The worker consumer follows the standard job worker pattern:
-
If the route completes successfully, the job is automatically completed. If the exchange body is a
Map, those entries are passed as output variables. -
If the route throws an exception, the job is automatically failed with the exception message. The retry count is decremented by one.
-
If the route explicitly calls
completeJob,failJob, orthrowError, the auto-complete is skipped (the consumer detects this via theCamundaJobHandledexchange property).
Basic Example — process a job (auto-completed on success):
-
Java
-
YAML
-
XML
from("camunda://worker?jobType=myJobType&timeout=20")
.process(exchange -> {
JobWorkerMessage body = exchange.getIn().getBody(JobWorkerMessage.class);
if (body != null) {
long key = body.getKey();
String type = body.getType();
Map<String,String> customHeaders = body.getCustomHeaders();
long processInstanceKey = body.getProcessInstanceKey();
String bpmnProcessId = body.getBpmnProcessId();
Map<String,Object> variables = body.getVariables();
}
}); - route:
from:
uri: "camunda://worker?jobType=myJobType&timeout=20"
steps:
- log:
message: "Received job ${header.CamelCamundaJobKey}" <route>
<from uri="camunda://worker?jobType=myJobType&timeout=20"/>
<log message="Received job ${header.CamelCamundaJobKey}"/>
</route> Returning output variables — set the body to a Map to pass variables back:
-
Java
-
YAML
-
XML
from("camunda://worker?jobType=myJobType&timeout=20")
.process(exchange -> {
Map<String, Object> result = new HashMap<>();
result.put("approved", true);
exchange.getIn().setBody(result);
}); - route:
from:
uri: "camunda://worker?jobType=myJobType&timeout=20"
steps:
- setBody:
constant:
resultType: "java.util.Map"
expression: "" <route>
<from uri="camunda://worker?jobType=myJobType&timeout=20"/>
<process ref="myJobProcessor"/>
</route> Advanced Worker Flow Examples
For advanced scenarios, you can explicitly call completeJob, failJob, or throwError in the route. When you do, the consumer skips auto-complete/auto-fail.
-
Throw a business error — signals a BPMN error with an error code and message:
-
Java
-
YAML
-
XML
from("camunda://worker?jobType=myJobType&timeout=20")
.process(exchange -> {
exchange.getIn().setHeader(CamundaConstants.ERROR_CODE, "INVALID_DATA");
exchange.getIn().setHeader(CamundaConstants.ERROR_MESSAGE, "Data validation failed");
})
.to("camunda://throwError"); - route:
from:
uri: "camunda://worker?jobType=myJobType&timeout=20"
steps:
- setHeader:
name: CamelCamundaErrorCode
simple: "INVALID_DATA"
- setHeader:
name: CamelCamundaErrorMessage
simple: "Data validation failed"
- to:
uri: "camunda://throwError" <route>
<from uri="camunda://worker?jobType=myJobType&timeout=20"/>
<setHeader name="CamelCamundaErrorCode">
<simple>INVALID_DATA</simple>
</setHeader>
<setHeader name="CamelCamundaErrorMessage">
<simple>Data validation failed</simple>
</setHeader>
<to uri="camunda://throwError"/>
</route> Migrating from camel-zeebe
The camel-camunda component is the successor of camel-zeebe. Key differences:
-
Uses the new
io.camunda:camunda-client-javalibrary instead ofio.camunda:zeebe-client-java -
URI scheme changes from
zeebe:tocamunda: -
Component options use
grpcAddress/restAddressinstead ofgatewayHost/gatewayPort -
Supports Camunda SaaS via
clusterId,region,clientId,clientSecret -
Consumer
jobKeyparameter is renamed tojobType(for clarity) -
Request/response model classes are in
org.apache.camel.component.camunda.modelinstead oforg.apache.camel.component.zeebe.model