'Flowable correlation catch event happens before data is persisted
As far as I am aware of, data is persisted in Flowable when it reaches a waiting state.
In our process we have a delegate which are starting a calculation and logging an ID for tracking purposes, and waits for a JMS message to restart the flow, like this:
In the "Start Calculation" delegate we have code like this:
String id = calculationService.startCalculation().getId();
execution.setVariable(CORRELATION_KEY, id);
loggingService.updateCase(id);
Both this calculation and this logging takes some time. And sometimes the logging takes more time than the calculation - meaning that the JMS message arrives before the "Start Calculation" delegate is finished.
If this happens, the correlation:
ProcessInstance instance =
this.runtimeService.createProcessInstanceQuery()
.variableValueEquals(CORRELATION_KEY, correlationValue)
.singleResult();
Does not result in any answer, and the process will be waiting indefinite. Most of the time this is not a problem when logging is faster than the calculation.
How can I solve this, I haven't found any methods to force persisting of variables before the delegate is finished. I guess I can wait for a minute and try again in the MessageHandler class, but as there are many JMS messages coming, but only a few that actually correlates, I feel that this will cause unnecessary noice.
Maybe if I move the logging to its own delegate, and uses an inclusive gateway to this and the catch event will solve it. But hoping for a more elegant solution.
Solution 1:[1]
I think what you are looking for is a TriggerableServiceTask. This task implements both execute() and trigger() methods which allows the process instance to move on after the external system responds. Check out this explanation and example: Restart flowable process from jms message listener
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Greg Harley |

