RevertHintStore
RevertHintStore
does provide you a map to put the data that the revert processes want.
After having a NonRetryableExecutorException, the engine will start the revert process by stopping to forward anymore.
You know already, when the transaction going forward, you can update or add the data in the aggregator object.
But when it is starting to revert, you cannot change the values in the aggregator object anymore.
Because the aggregator object is frozen.
Therefore, you should have to have a way to carry out the data to the backwards as well.
To overcome that problem, the system provides the RevertHintStore object to add your extra hints that are necessary for the revert process through each executor.
After adding the data in the RevertHintStore
object, you can read that data from other next revert-processes.
Here you can see an implementation for revert method of one of command executors.
RevertHintStore
can be used in all revert processes like revert-before,
revert-after executors as well.
@SagaExecutor(
executeFor = "delivery-service",
liveCheck = true,
value = "DispatchOrderExecutor"
)
public class DispatchOrderExecutor implements CommandExecutor<PlaceOrderAggregator> {
@Override
public ProcessStepManager<PlaceOrderAggregator> doProcess(
ProcessStack processStack,
PlaceOrderAggregator aggregator,
ProcessStepManagerUtil<PlaceOrderAggregator> stepManager
) throws RetryableExecutorException, NonRetryableExecutorException {
//
}
@Override
public void doRevert(ProcessStack processStack,
NonRetryableExecutorException realException,
PlaceOrderAggregator aggregator,
RevertHintStore revertHintStore
) throws RetryableExecutorException {
revertHintStore
.get("MakePaymentExecutor") (1)
.ifPresent(makePaymentExecutor -> {
if (makePaymentExecutor.equalsIgnoreCase("success")) {
(2)
revertHintStore.put("last_updated_time", LocalDateTime.now().toString());
(2)
revertHintStore.put("DispatchOrderExecutor", "success");
}
});
...
}
}
1 | Obtaining the RevertHintStore data (Key: MakePaymentExecutor) that have been added in another revert process before.
If the value exists in the RevertHintStore you will have an Optional<String> object with the data. |
2 | Based on the RevertHintStore 's old data that bes been added by another executor, adding another data into the RevertHintStore .
This value will be helpful for the next revert process. |