Spring Boot + Kafka + Camunda 8 Project Example

 Modern microservices architectures rely heavily on event-driven communication. In this article, we will build a real example project combining:

  • Spring Boot

  • Apache Kafka

  • Camunda 8

This project demonstrates how to:

  • Start a workflow from a Kafka event

  • Publish Kafka events from Camunda

  • Handle asynchronous orchestration

  • Maintain clean separation of concerns


🎯 Use Case: Order Processing System

Scenario:

  1. An Order Service publishes an event to Kafka.

  2. A Kafka Consumer receives the event.

  3. Camunda 8 starts a workflow.

  4. The workflow triggers a Payment Service.

  5. Payment result is published back to Kafka.

  6. Camunda correlates the message and completes the process.


🏗 Architecture Overview


Components:

  • Spring Boot App

  • Kafka Broker

  • Camunda 8 (Zeebe)

  • Payment Worker


🛠 Step 1: Project Setup

Create Spring Boot project with:

Dependencies:

  • Spring Web

  • Spring Kafka

  • Camunda Zeebe Client

  • Lombok


📦 Maven Dependencies

<dependency> <groupId>io.camunda</groupId> <artifactId>zeebe-client-java</artifactId> <version>8.x.x</version> </dependency> <dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring-kafka</artifactId> </dependency>

🚀 Step 2: Start Camunda 8 (Local)

Use Docker:

docker compose up

Or connect to Camunda SaaS.


📨 Step 3: Kafka Producer (Order Event)

@Service @RequiredArgsConstructor public class OrderProducer { private final KafkaTemplate<String, String> kafkaTemplate; public void sendOrder(String orderJson) { kafkaTemplate.send("order-created", orderJson); } }

📥 Step 4: Kafka Consumer → Start Camunda Process

@KafkaListener(topics = "order-created") public void consume(String message) { zeebeClient.newCreateInstanceCommand() .bpmnProcessId("order-process") .latestVersion() .variables(message) .send() .join(); }

This starts the workflow.


📊 Step 5: BPMN Model

Basic BPMN Flow:


Service Task type: process-payment


🔄 Step 6: Job Worker → Publish Payment Event

@JobWorker(type = "process-payment") public void processPayment(ActivatedJob job) { kafkaTemplate.send("payment-request", job.getVariables()); jobClient.newCompleteCommand(job.getKey()) .send() .join(); }

🔔 Step 7: Payment Service → Publish Result

@KafkaListener(topics = "payment-request") public void processPayment(String message) { kafkaTemplate.send("payment-completed", message); }

🔗 Step 8: Kafka → Correlate Message to Camunda

@KafkaListener(topics = "payment-completed") public void correlate(String message) { zeebeClient.newPublishMessageCommand() .messageName("PaymentCompleted") .correlationKey(extractOrderId(message)) .variables(message) .send() .join(); }

⚠ Important Production Considerations

1️⃣ Idempotency

Kafka may deliver duplicates.
Always ensure process instances are unique by business key.


2️⃣ Retry Strategy

Use:

  • Zeebe retry mechanism

  • Kafka retry topics

  • Dead letter queue


3️⃣ Error Handling

Use BPMN:

  • Boundary error events

  • Incident monitoring


4️⃣ Monitoring

Monitor:

  • Kafka lag

  • Zeebe backpressure

  • Job failure rate


🧠 Why This Architecture Works

  • Kafka handles high-volume events.

  • Camunda handles business orchestration.

  • Spring Boot keeps services modular.

  • Each component scales independently.

This is a clean enterprise-grade pattern.


📌 Final Thoughts

This example shows how to combine:

  • Event streaming (Kafka)

  • Workflow orchestration (Camunda 8)

  • Business logic (Spring Boot)

This architecture is widely used in:

  • FinTech

  • E-commerce

  • Logistics

  • Enterprise SaaS


💼 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, Azure, CMS and workflow automation (jBPM, Camunda BPM, RHPAM).

Comments

Popular posts from this blog

Scopes of Signal in jBPM

OOPs Concepts in Java | English | Object Oriented Programming Explained

jBPM Installation Guide: Step by Step Setup