Spring Boot + Camunda External Task Pattern (Complete Guide)

 In enterprise workflows, long-running business logic should not execute inside the workflow engine.

Instead, Camunda uses the External Task Pattern — where workers fetch tasks and process them independently.

This is the most scalable way to integrate microservices with BPM.

In this guide you will learn:

  • What External Tasks are

  • Why they are important

  • How to implement using Spring Boot

  • Best practices for production


📌 What is the External Task Pattern?

In Camunda Platform, a Service Task can be executed outside the engine.

Instead of pushing work → the worker pulls the job.

So the engine never blocks.


🖼️ External Task Architecture


🧠 Why External Tasks?

Traditional Service Task:

Engine calls service directly
→ Tight coupling
→ Failures block workflow

External Task:

Worker fetches job
→ Loose coupling
→ Retry possible
→ Highly scalable


🛠 Step 1: Create External Service Task in BPMN

In Modeler:

Service Task → Type = External

Topic name example:

payment-service

Now Camunda waits for a worker.


🛠 Step 2: Add Dependencies in Spring Boot

<dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter-external-task-client</artifactId> </dependency>

🛠 Step 3: Configure Worker

camunda: bpm: client: base-url: http://localhost:8080/engine-rest async-response-timeout: 10000

🛠 Step 4: Implement External Task Worker

@Component @ExternalTaskSubscription("payment-service") public class PaymentWorker implements ExternalTaskHandler { @Override public void execute(ExternalTask task, ExternalTaskService service) { String orderId = task.getVariable("orderId"); System.out.println("Processing payment for " + orderId); service.complete(task); } }

Worker automatically polls tasks.


🖼️ Worker Execution Flow


🔁 Retry & Failure Handling

If service fails:

service.handleFailure( task, "Payment failed", "Gateway timeout", 3, 60000 );

Camunda retries automatically.


🔐 Lock Duration

Worker locks job while processing.

Prevents multiple workers executing same task.

Example:

lockDuration = 10000 ms

🧪 Complete Flow

  1. Process reaches service task

  2. Engine creates external task

  3. Worker fetches task

  4. Worker executes logic

  5. Worker completes task

  6. Process continues


⚠️ Common Mistakes

❌ Short lock duration
❌ No retries configured
❌ Business logic inside engine
❌ Blocking API calls


🏆 Production Best Practices

✔ Use multiple workers
✔ Idempotent services
✔ Configure retries
✔ Separate microservices
✔ Monitor failures


🎯 When to Use External Tasks

Use for:

  • Microservices

  • Remote APIs

  • Long processing

  • Payment gateways

  • Third-party integrations

Avoid for:

  • Simple Java logic

  • Short execution


🎯 Conclusion

External Task Pattern makes Camunda:

  • Scalable

  • Resilient

  • Microservice-friendly

It is the recommended approach for enterprise integration.


Recommended Reading


💼 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).

📧 Contact: ishikhanirankari@gmail.com | info@realtechnologiesindia.com

🌐 Website: IT Trainings | Digital metal podium     


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