Camunda 8 Service Task with Java
In Camunda 8, a Service Task is executed by a Job Worker (external worker). In Spring Boot, the easiest way to implement this is with @JobWorker, where the job type (a.k.a. task type) in the BPMN matches the worker’s type.
This blog shows a complete working example: BPMN service task → Java worker → update variables → handle failures.
1) BPMN: Configure the Service Task (Job Type)
In Camunda Modeler:
-
Add a Service Task
-
Set Implementation to Job Worker (or “External” depending on Modeler version)
-
Set Type to:
payment-worker(example) -
(Optional) Set Retries:
3
Important: The Type must match the Java worker annotation:
2) Spring Boot Dependencies (Maven)
Use Camunda 8 Spring Boot starter (Zeebe):
If you’re using an older setup, you may see
io.camunda.spring:zeebe-spring-boot-starter. Use whichever matches your project, but the concept remains the same.
3) Configuration (application.yaml)
If you run Camunda 8 locally (Self-Managed)
You’ll typically configure the Zeebe gateway connection:
If you use Camunda 8 SaaS
You configure clusterId / clientId / clientSecret etc. (different block). Share your mode if you want the exact config.
4) Java Worker Example (@JobWorker) — Read + Update Variables
Here’s a clean worker that:
-
reads process variables (
orderId,amount) -
does some business logic
-
returns variables (
txnId,paymentStatus)
✅ Why autoComplete=true is nice
It automatically completes the job after the method returns successfully.
5) Failure Handling (Retries + Incidents)
In real projects, jobs fail. You should:
-
throw an exception to trigger retries
-
or use a BPMN Error pattern if you want a modeled error path
Option A: Throw Exception → Zeebe retries
If retries become 0, Camunda will create an Incident visible in Operate.
Option B: Manual control (autoComplete=false)
Useful when you want full control over complete/fail:
6) Variable Mapping Tip (Avoid “null” surprises)
If your DMN/service tasks depend on variables, prefer:
-
consistent variable names (
orderId,amount) -
JSON-friendly structures (Camunda 8 is JSON-first)
-
input/output mapping in BPMN if needed
Example: map amount into a nested object:
-
payment.amount = amount
7) How to Test Quickly (Local)
Minimum steps:
-
Start Camunda 8 (Docker Compose)
-
Deploy BPMN from Modeler
-
Start a process instance (with variables)
-
Run your Spring Boot app
-
Watch the service task complete in Operate
Sample start variables:
8) Common Mistakes (That Cause “Worker Not Picking Job”)
-
Job type mismatch: BPMN type ≠
@JobWorker(type="...") -
Worker not running / not connected to gateway
-
Wrong gateway address/port
-
Auth enabled but not configured (SaaS/self-managed mismatch)
-
Variables are missing or wrong type (e.g., amount is string not number)
Conclusion
In Camunda 8, a Service Task is executed by a Job Worker. With Spring Boot, @JobWorker is the simplest way to:
-
subscribe to a job type
-
implement business logic
-
update process variables
-
handle failures and retries cleanly
💼 Professional Support Available
If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.
Technologies covered include Java, Spring Boot, PL/SQL, CMS, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).
📧 Contact: ishikhanirankari@gmail.com | info@realtechnologiesindia.com
🌐 Website: IT Trainings | Digital metal podium
Comments
Post a Comment