Quick question about External Task and their usage

Hi @francesco_giberti,

Camunda External Task Client allows to set up remote Service Tasks for your workflow.

The process engine supports two ways of executing service tasks:

  1. Internal Service tasks: Synchronous invocation of code deployed along with a process application.

  2. 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.


image



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:



5 Likes