Spring Boot + Camunda Service Task Java Example

A service task in Camunda is a task type that executes automated work, typically by calling external services, executing code, or integrating with other systems. It's represented by a gear icon in BPMN diagrams.
Implementation Types:
- Java Delegate
- Expression
- Delegate Expression
- External Service Task
- Connector
Video
This tutorial is explained in the below Youtube Video.Spring Boot Camunda Tutorials
Spring Boot + Camunda Hello World Example. Spring Boot + Camunda Script Task Example. Spring Boot + Camunda Service Task Example. Spring Boot + Camunda Service Task - Delegate Expression Example. Spring Boot + Camunda Service Task - Expression Example.
Implementation
Download the source code we had implemented in Spring Boot 3 + Camunda Script Task example tutorial.We will be modifying the project to add the java service class for sending mail confirmations.

It overrides the execute method required by the JavaDelegate interface.
Retrieves two process variables using execution.getVariable():
- orderTotal: Contains the transaction amount
- paymentStatus: Contains the status of the payment
We now modify the TestController class to use the bpmn with id - third-javainuse
package com.example.delegate; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; public class ConfirmationEmailDelegate implements JavaDelegate { @Override public void execute(DelegateExecution execution) throws Exception { System.out.println("Sending mail that transaction of order of amount " + execution.getVariable("orderTotal") + " is a " + execution.getVariable("paymentStatus")); } }