I have 3 microservices and am trying to implement compensation activity for each service. Now let say after an error compensation event triggered and now this compensation activity itself throwing error. If compensation activity fails, i want to retry it for 5 times. Here is the sample code i have implemented but its not working. Any suggestions on this.
public static BpmnModelInstance createSaga() {
// define saga as BPMN process
ProcessBuilder flow = Bpmn.createExecutableProcess("poc");
// - flow of activities and compensating actions
flow.startEvent()
.serviceTask("Project2").name("Save Project2").camundaClass(SaveProject2.class)
.boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone()
.compensationStart().serviceTask("RollbackProject2").camundaClass(RollbackProject2.class).camundaFailedJobRetryTimeCycle("R5/PT5S").compensationDone()
.serviceTask("Project3").name("Save Project3").camundaClass(SaveProject3.class)
.boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone()
.compensationStart().serviceTask("RollbackProject3").camundaFailedJobRetryTimeCycle("R5/PT1M").camundaClass(RollbackProject3.class).compensationDone()
.serviceTask("Project4").name("Save Project4").camundaClass(SaveProject4.class)
.boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone()
.compensationStart().serviceTask("RollbackProject4").camundaClass(RollbackProject4.class).compensationDone()
.endEvent();
// - trigger compensation in case of any exception (other triggers are possible)
flow.eventSubProcess()
.startEvent().error("java.lang.Throwable")
.intermediateThrowEvent().compensateEventDefinition()
.compensateEventDefinitionDone()
.endEvent();
// ready
BpmnModelInstance saga = flow.done();