Camunda External Task Client allows to set up remote Service Tasks for your workflow.
The process engine supports two ways of executing service tasks:
-
Internal Service tasks: Synchronous invocation of code deployed along with a process application.
-
External tasks: Providing a unit of work in a list that can be polled by workers.
-
Process engine publishes a unit of work to a worker to fetch and complete, and this process is called as external task pattern.
-
Pull approach, where external worker threads query Camunda for “external service tasks”.
-
Pull a service task into an external worker thread and inform process engine of completion.
-
Read about the External Task Pattern and usage of ExternalTaskService.
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(10, "externalWorkerId")
.topic("AddressValidation", 60L * 1000L)
.execute();
for (LockedExternalTask task : tasks) {
try {
String topic = task.getTopicName();
// work on task for that topic
...
// if the work is successful, mark the task as completed
if(success) {
externalTaskService.complete(task.getId(), variables);
}
else {
// if the work was not successful, mark it as failed
externalTaskService.handleFailure(
task.getId(),
"externalWorkerId",
"Address could not be validated: Address database not reachable",
1, 10L * 60L * 1000L);
}
}
catch(Exception e) {
//... handle exception
}
}
Refer the equivalent rest api for externalTaskService.fetchAndLock() and the rest api for externalTaskService.complete().
Reference blogs for External Tasks are:
- https://blog.camunda.com/post/2015/11/external-tasks/
- Invoking services from a Camunda 7 process | Camunda Platform 8
- https://blog.camunda.com/post/2017/10/extending_locks_of_external_tasks/
- https://blog.camunda.com/post/2017/08/remote-workers-and-idempotency/