Hi,
I am new to Camunda platform. I have done the set up of camunda platform in my local machine using docker compose. I am successful in running a simple process.
But what I want to know is, how to return back the response of worker logic to the start task?
I have spring boot project where I am triggering the process to start.
Here is my process
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:zeebe="http://camunda.org/schema/zeebe/1.0" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0t46ymm" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.13.0" modeler:executionPlatform="Camunda Cloud" modeler:executionPlatformVersion="8.2.0">
<bpmn:process id="Process_1pul748" name="start" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" name="start">
<bpmn:outgoing>Flow_18vnagg</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_18vnagg" sourceRef="StartEvent_1" targetRef="test_task1" />
<bpmn:serviceTask id="test_task1" name="test_task">
<bpmn:extensionElements>
<zeebe:taskDefinition type="testTenantAPI" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_18vnagg</bpmn:incoming>
<bpmn:outgoing>Flow_03g5wjm</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_197jvv8" name="end">
<bpmn:incoming>Flow_03g5wjm</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_03g5wjm" sourceRef="test_task1" targetRef="Event_197jvv8" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1pul748">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="186" y="142" width="22" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1mwnd4m_di" bpmnElement="test_task1">
<dc:Bounds x="270" y="77" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_197jvv8_di" bpmnElement="Event_197jvv8">
<dc:Bounds x="432" y="99" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="441" y="142" width="19" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_18vnagg_di" bpmnElement="Flow_18vnagg">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_03g5wjm_di" bpmnElement="Flow_03g5wjm">
<di:waypoint x="370" y="117" />
<di:waypoint x="432" y="117" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Here is pom xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.14</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.orchestration</groupId>
<artifactId>camunda</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>camunda</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.camunda/spring-zeebe-starter -->
<dependency>
<groupId>io.camunda</groupId>
<artifactId>spring-zeebe-starter</artifactId>
<version>8.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is my worker
@Component
public class Worker {
private static final Logger LOG = LogManager.getLogger(Worker.class);
@ZeebeWorker(type = "testTenantAPI", autoComplete = true)
public ResponseDto test(final ActivatedJob job, @ZeebeVariablesAsType SampleDto sampleDto) {
LOG.debug("worker job called " + sampleDto.getAge());
// Business logic to be added
ResponseDto responseDto = new ResponseDto();
responseDto.setId("001");
responseDto.setMessage("Success");
return responseDto;
}
}
Here is my controller
@PostMapping(value = "api/v1/test/camunda")
public void test(@RequestBody SampleDto sampleDto) {
try {
client.newDeployResourceCommand().addResourceFromClasspath("testTenantFlow.bpmn").send().join();
final ProcessInstanceEvent event = client.newCreateInstanceCommand().bpmnProcessId("Process_1pul748")
.latestVersion().variables(sampleDto).send()
.join();
LOG.info(
"Started instance for processDefinitionKey='{}', bpmnProcessId='{}', version='{}' with processInstanceKey='{}'",
event.getProcessDefinitionKey(), event.getBpmnProcessId(), event.getVersion(),
event.getProcessInstanceKey());
} catch (Exception e) {
e.printStackTrace();
LOG.debug("Exception " + e.getMessage());
}
}
How I am triggering the flow
http://localhost:8080/api/v1/test/camunda with payload
{
“name”:“karthi”,
“age”:25
}
I am excepting the output for the API as
{
“id”:“001”,
“message”:“Success”
}
How can I get the return value of worker to the start task(which I am hitting it using above URL)