So we took a different approach as we wanted to use our own human task server. We thought that if we will be notified about changes occurring inside Activiti's engine concerning user tasks (e.g. create task event), we could propagate those notifications to our Human Task Service. Unfortunately, we found out that Activiti's engine does not have a notification mechanism as we hoped (at least in 5.8 - there are talking about an event bus in future releases), so we had to use another mechanism to achieve this task.
Apparently Activiti does have a notification mechanism while parsing a BPMN process definition XML. It allows one to plug in a listener which will be notified in several events. One of those events is when a user task is being parsed. This was exactly what we needed. We plugged our own listener implementation and every time a user task was parsed we added a TaskListenr to the user task in the process definition. This listener was invoked by the engine when this task was created. Obviously the listener impl is to simply send a notification as "Task Created" to our own Human Task Service. Note: you will also have to manage the task life-cycle and update Activiti's engine using its services.
Now for the technical details. As in our latest post, this requires:
- adding a Java class implementing BpmnParseListener. This is the interface you want to implement to plug in your own listener.
- injecting the Java class using the Spring xml config file.
We implement a TaskListener for each of the events we are interested in:
We Override the parseUserTask method so that in each time a parse event occurs our TaskListeners will add some logic on our WS-HumanTask Service/Task Service. The rest of the parse events will be ignored.
The Spring file change will be done in our context XML file:
That's it. You are good to go and handle tasks on your own. Good luck.