Camunda help with TaskListener and ExecutionListener

Hi, i am new to camunda.

First i’m using spring boot starter with examples from https://github.com/camunda/camunda-bpm-examples/tree/master/spring-boot-starter.

I’m kind of confused with TaskListener and ExecutionListener. I use them with spring-native event-bridge.

A few questions

I have a TaskListener like this:

    @EventListener(condition = "#event.eventName=='create'")
    public void onTaskCreatedEvent(TaskEvent event) {
        // handle immutable task event
        log.info("handle task event {} for task id {}", event.getEventName(), event.getId());
    }

    @EventListener(condition = "#event.eventName=='complete'")
    public void onTaskCompletedEvent(TaskEvent event) {
        // handle immutable task event
        log.info("handle task event {} for task id {}", event.getEventName(), event.getId());
    }
  • Does this listener is triggered only on user task type ? If yes, how to do the same thing with for instance all service task type without impact in bpmn files ?

I already see this post : https://github.com/camunda/camunda-bpm-examples/tree/master/process-engine-plugin/bpmn-parse-listener-on-user-task but can’t manage to handle event for all service task.

  • How to handle ‘open task’ event ?

I also use ExecutionListener, but:

  • How to simply handle started and completed events of BPM process (i.e. with and EventListener and condition) ?

I already see this commit disclaimer · camunda-community-hub/camunda-platform-7-reactor@315c399 · GitHub for amunda-bpm-reactor

Thanks !

@keuss, TaskListener is applicable only for UserTask types and ExecutionListener is common for all types like, Start/End events, boundary events, usertasks, service tasks, call activity, embedded sub process, sequence flows, etc.

Event types for ExecutionListener are start and end. Read about ExecutionListener and events.

  • Start and end of a process instance.
  • Taking a transition.
  • Start and end of an activity.
  • Start and end of a gateway.
  • Start and end of intermediate events.
  • Ending a start event or starting an end event.

For TaskListeners, read about TaskListeners and task-listener-event-lifecycle.

TaskListeners Events are:

  • create
  • update
  • assignment
  • timeout
  • complete
  • delete

Read about Managing The Task Lifecycle. and enhanced-bpmn-execution in v7.12.

2 Likes

Thanks,

But how i can simply manage start and end of a process instance with an EventListener annotation and his condition ?

I can find which event is related to the start and end of a process.

Refer the docs for Spring Eventing Bridge.

 public class ExampleExecutionListenerOne implements ExecutionListener {
    public void notify(DelegateExecution execution) throws Exception {
      // can access instances of process engine services and delegateExecution
    }
  }

I begin to understand, but for ExecutionListener is it possible to retreive the associated ‘object type’ from which event is launched ?

  • Process
  • Activity
  • Transition

@keuss,

public class ExampleExecutionListenerOne implements ExecutionListener {

    public void notify(DelegateExecution execution) throws Exception {
       // can access instances of process engine services and delegateExecution

       execution.getCurrentActivityId(); //activity       

       execution.getCurrentActivityName(); //activity       

       execution.getProcessDefinitionId(); //process

       execution.getEventName(); // type of event
       
       //type of activity including transitions
       String activityType = execution.getBpmnModelElementInstance()
                               .getElementType().getTypeName();
     }
  }

I was using ExecutionEvent and not DelegateExecution.

Thanks