Notify when tasks list changed

cancel
Showing results for 
Search instead for 
Did you mean: 
filip_majernik
Member II

Notify when tasks list changed

I have an application with lot of modules, one of them is the activiti BPM engine. I use elasticsearch (ES) as the datastore. There is also a web application, which serves as a trigger to executing the processes and providing data. Every process has its instance in the ES and the available list of tasks (the mapping to the activiti task instances) is also stored in the process metadata. I've been playing around with synchronization of the tasks list between the BPM engine and the datastore and I am still not satisfied. What I am doing is following - the workflow of the application:

  1. Create a new case (which is modeled by the BPMN process) in the ES and get the ID.
  2. Start the process in the activiti engine and associating it with the ID from step 1 using the businessKey parameter.
  3. Update the tasks list in the ES using a TaskListener with an expression (which calls a method on a java class) on the createEvent of every task.

The problems are following. First of all I would need to define such a TaskListener on every task in the process (there are about 150 complex processes). Second problem is, that the when the TaskListener is called and query the engine for the tasks I am not getting the just created task in there (I suppose this is because of the listener being called before the task entity is created, or the transaction committed).

So the question is, what is the best way to configure some kind of a global listener for the engine which notifies me every time when there is something changed with any process from the deployment so I can query the tasks list and update the ES? 

Thank you,

Filip

3 Replies
gdharley
Intermediate

Re: Notify when tasks list changed

Not sure what version of Activiti you are using, but if it is something relatively new, I would make use of the Event Handler mechanism that was added to the engine about a year ago:

Activiti User Guide - Event Dispatcher 

Event handlers can be defined globally or for an individual process instance and can be mapped to a number of standard events (such as task creation).

Adding a global listener to the TASK_CREATED event should satisfy your needs.

Greg

filip_majernik
Member II

Re: Notify when tasks list changed

This is indeed possible. But the problem still is that the transaction most probably has not been completed yet. This way you can obtain the TASK entity, but when you in this moment query the BPM Runtime to get the list of tasks, it would not be present in the list.

gdharley
Intermediate

Re: Notify when tasks list changed

Actually, the event listener is not triggered until after the commit operation, so the task entity should actually be retrievable.

Greg