Activiti listener db updates - are they atomic ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 01:44 PM
Hi Members,
I have written event listeners for events - PROCESS_STARTED and TASK_CREATED. In the event listener I am calling my custom db inserts (these are not activiti tables) for PROCESS_STARTED and TASK_CREATED. For PROCESS_STARTED, it inserts record into 'workflow' table and for TASK_CREATED, it inserts record into 'task' table. When I start the process by API i.e. runtimeService.startProcessInstanceByKey(workflowKey, businessKey, variables), I see that following events are emitted in the order - PROCESS_STARTED and TASK_CREATED (there are other events emitted by Activiti engine but I am only interested in these events). Tracing the execution of my code, the data got inserted into the workflow table. As there was exception in the insertion of task table for the TASK_CREATED event, the call failed. Later when I check the workflow table, I do not see any entries for workflow. Are the external insertion/updates atomic.
Thanks
I have written event listeners for events - PROCESS_STARTED and TASK_CREATED. In the event listener I am calling my custom db inserts (these are not activiti tables) for PROCESS_STARTED and TASK_CREATED. For PROCESS_STARTED, it inserts record into 'workflow' table and for TASK_CREATED, it inserts record into 'task' table. When I start the process by API i.e. runtimeService.startProcessInstanceByKey(workflowKey, businessKey, variables), I see that following events are emitted in the order - PROCESS_STARTED and TASK_CREATED (there are other events emitted by Activiti engine but I am only interested in these events). Tracing the execution of my code, the data got inserted into the workflow table. As there was exception in the insertion of task table for the TASK_CREATED event, the call failed. Later when I check the workflow table, I do not see any entries for workflow. Are the external insertion/updates atomic.
Thanks
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2016 11:37 PM
I was able to get to understand the problem. I am using Spring boot and I have defined the JPATransactionManager for my database and it is being used by Activiti. Hence if there is any exception in event listener calling my code, the db rollbacks for my table are done. I have defined the bean for datasource defining the Activiti database as primary. But I am not sure how Activiti is using the TransactionManager of my database and working properly. The Spring documentation clearly mentions that if no transaction manager is created, it will create a default transactionmanager. But if any transaction manager is created, it will use it. Using the transaction manager of my database, Activiti is working fine. I am trying to understand this piece here. We are deploying to production and wanted to make sure I understand it properly. Can anybody shed some light here ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2016 05:17 AM
You inject the transaction manager into the Activiti process engine configuration. Activiti and the custom database calls will be done in the same transaction in that case (if they are the same datasource, with multiple you need XA datasources).
