Camunda events CDI question - how to get just one event by transaction?

Hi guys,

I use the following event handler:

public void onProcessPayrollAfterTxCommitEvent(@Observes(during = TransactionPhase.BEFORE_COMPLETION) @BusinessProcessDefinition("payroll") BusinessProcessEvent businessProcessEvent) {

And I get the following logged events:

12:58:38,566 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: tskCalculatePayroll - taskId: null - transitionName: SequenceFlow_7 - type: start
12:58:38,571 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: StartEvent_2 - taskId: null - transitionName: SequenceFlow_7 - type: take
12:58:38,573 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: StartEvent_2 - taskId: null - transitionName: null - type: end
12:58:38,574 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: StartEvent_2 - taskId: null - transitionName: null - type: start
12:58:38,574 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: SubProcess_1 - taskId: null - transitionName: SequenceFlow_1 - type: start
12:58:38,574 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: miProcessStarted - taskId: null - transitionName: SequenceFlow_1 - type: take
12:58:38,575 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: miProcessStarted - taskId: null - transitionName: null - type: end
12:58:38,575 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: miProcessStarted - taskId: null - transitionName: null - type: start
12:58:38,575 INFO (Camel (camel-2) thread #52 - JmsConsumer[EP_QUEUE_NEW_MASSIVE_PAYROLL]) activityId: miProcessStarted - taskId: null - transitionName: null - type: start
12:58:49,090 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: tskGeneratePayslipDraft - taskId: null - transitionName: SequenceFlow_10 - type: start
12:58:49,090 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: ExclusiveGateway_2 - taskId: null - transitionName: SequenceFlow_10 - type: take
12:58:49,091 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: ExclusiveGateway_2 - taskId: null - transitionName: null - type: end
12:58:49,091 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: ExclusiveGateway_2 - taskId: null - transitionName: SequenceFlow_17 - type: start
12:58:49,091 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: miPayrollCalculated - taskId: null - transitionName: SequenceFlow_17 - type: take
12:58:49,092 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: miPayrollCalculated - taskId: null - transitionName: null - type: end
12:58:49,092 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: miPayrollCalculated - taskId: null - transitionName: SequenceFlow_2 - type: start
12:58:49,092 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: tskCalculatePayroll - taskId: null - transitionName: SequenceFlow_2 - type: take
12:58:49,093 INFO (Camel (camel-2) thread #55 - JmsConsumer[EP_QUEUE_CALCULATEPAYROLLS]) activityId: tskCalculatePayroll - taskId: null - transitionName: null - type: end
12:58:54,960 INFO (Camel (camel-2) thread #68 - JmsConsumer[EP_QUEUE_PAYSLIP]) activityId: null - taskId: 59257c3b-0615-11ea-8fbd-00090ffe0001 - transitionName: null - type: create
12:58:54,960 INFO (Camel (camel-2) thread #68 - JmsConsumer[EP_QUEUE_PAYSLIP]) activityId: null - taskId: 59257c3b-0615-11ea-8fbd-00090ffe0001 - transitionName: null - type: assignment
12:58:54,961 INFO (Camel (camel-2) thread #68 - JmsConsumer[EP_QUEUE_PAYSLIP]) activityId: tskValidatePayroll - taskId: null - transitionName: SequenceFlow_14 - type: start
12:58:54,961 INFO (Camel (camel-2) thread #68 - JmsConsumer[EP_QUEUE_PAYSLIP]) activityId: tskGeneratePayslipDraft - taskId: null - transitionName: SequenceFlow_14 - type: take
12:58:54,961 INFO (Camel (camel-2) thread #68 - JmsConsumer[EP_QUEUE_PAYSLIP]) activityId: tskGeneratePayslipDraft - taskId: null - transitionName: null - type: end

There are just three threads here (#52, #55, #68), and my goal is to get just the very last event of every tx, but involving any task or activity in that process. For instance, if there is a tx where a ServiceTask is called and the transaction ends with an start event of a UserTask then I’d like the filter to give me just that very last event (start UserTask). I also would like to get rid of events involving flows… How could I narrow that?

The only annotations I have now are @StartTask(“taskName”) or similar annotations, where I must tell which is the activity to track, but my intention is to be informed only once but at the end of every tx.

I keep looking forward for your answer
Best regards
Alfonso.

I have the same problem.

I would like to update my UI after an asynchronous execution via end transaction event.

What would be the best way to achieve this?.

Best regards,