Service Tasks

A service task represents a work item in the workflow with a specific type.

workflow

When a service task is entered then a corresponding job is created. The workflow instance stops at this point and waits until the job is completed.

A worker can subscribe to the job type, process the jobs and complete them using one of the Zeebe clients. When the job is completed, the service task gets completed and the workflow instance continues.

Task Definition

A service task must have a taskDefinition. It specifies the type of job which workers can subscribe to.

Optionally, a taskDefinition can specify the number of times the job is retried when a worker signals failure (default = 3).

Task Headers

A service task can define an arbitrary number of taskHeaders. They are static metadata that are handed to workers along with the job. The headers can be used as configuration parameters for the worker.

Variable Mappings

By default, all job variables are merged into the workflow instance. This behavior can be customized by defining an output mapping at the service task.

Input mappings can be used to transform the variables into a format that is accepted by the job worker.

Additional Resources

XML representation

A service task with a custom header:

<bpmn:serviceTask id="collect-money" name="Collect Money">
  <bpmn:extensionElements>
    <zeebe:taskDefinition type="payment-service" retries="5" />
    <zeebe:taskHeaders>
      <zeebe:header key="method" value="VISA" />
    </zeebe:taskHeaders>
  </bpmn:extensionElements>
</bpmn:serviceTask>

Using the BPMN modeler

Adding a service task:

service-task

Adding custom headers: task-headers

Adding variable mappings: variable-mappings

Workflow Lifecycle

Workflow instance records of a service task:

Intent Element Id Element Type
ELEMENT_ACTIVATING collect-money SERVICE_TASK
ELEMENT_ACTIVATED collect-money SERVICE_TASK
... ... ...
ELEMENT_COMPLETING collect-money SERVICE_TASK
ELEMENT_COMPLETED collect-money SERVICE_TASK

References: