cancel
Showing results for 
Search instead for 
Did you mean: 

Task listener is triggering create event before persisting task in DB

testactivitiuse
Champ in-the-making
Champ in-the-making
I have a workflow like this user task1 -service task —user task2

Now I want process to stop at usertask2 , a task listener is attached to usertask2 and listening on create event. When Create event is fired, a custom Java class publishes a JMS on queue.

There is another piece of Java code in a separate transaction listening to queue and triggers when message arrives,  here I am querying activiti DB for user task2 ID which is not in DB yet and throws exception. How could I resolve it? Is there any way to find whether task is persisted in DB before publishing message on queue?

BTW, we use 5.14 version.


3 REPLIES 3

jbarrez
Star Contributor
Star Contributor
" Is there any way to find whether task is persisted in DB before publishing message on queue?"

Yes, you need to CommandContextCloseListener and send the event when the transaction has been committed.
However, I'm pretty sure that CommandContextCloseListener is not available in 5.14 (any reason using such an old version?).
In that version, you'll probably have to use a Transaction listener (don't know the exact name anymore) where you wrap the logic in the post-commit callback.

shrey
Champ in-the-making
Champ in-the-making
Hi Joram,

Activiti has exposed Event as part of 5.15+. These are mentioned as part of activiti user guide under section 3.18 http://www.activiti.org/userguide/index.html#eventDispatcherEventTypes

can additional event listeners for events like TASK_CREATED, TASK_ASSIGNED help in identifying the creation of the usertask2 in above use case?

jbarrez
Star Contributor
Star Contributor
the events are different from what I answered above … that was about sending a CUSTOM event or data to something else.

But yes, the event listener can be used for this, but I think that a regular TaskListener is easier to use in this case.