This question is about the Camunda BPM engine.
I would like to implement an ExecutionListener that I can attach to any process events. This listener should send process state messages to a message queue. The process message should contain a state that would be "PENDING" for the process if the process is waiting in a UserTask somewhere.
Now I wonder if there is an easy way to find out if the process is waiting (somewhere) in a UserTask inside the Delegation Code (by using provided DelegateExecution
object of the delegation code method). Could not find one so far.
For example:
Note that this does not consider called process instances.
DelegateExecution does not have all the information that you need. You will have to use the task query to see whether it returns at least 1 result on the process instance that is currently running.
There is an interface
TaskListener
. You can implement it by yourself and append your ownTaskListener
to each UserTask in the BPMN code. You can also define on which event type your ownTaskListener
should be executed (create, assignment, complete, delete).The
notify
-method is called with aDelegateTask
which contains more specific information about the concrete UserTask. You could extract the information and send these information into your queue (when you call your implementation of theTaskListener
on the create event).Otherwise you can use the
TaskService
to create a query to retrieve all open tasks. For a working query you need the process instance id of the current execution, which you can retrieve from the delegate execution. To make things short take this code snippet:taskService.createTaskQuery().processInstanceId(delegateExecution.getProcessInstanceId()).list().isEmpty()
.