service task with “Retry Time Cycle” - how to “send a notification/throw a message” on each retry
Hello,
I have a service task with a “Retry Time Cycle” configured. When there is no retries left a BpmnError is thrown (working perfectly).
I would like also to be able to send a notification on each retry to notify a third party service that the service task is still running and is performing retries.
I tried to implement this feature using the runtime service and the createMessageCorrelation method but this is not working (probably because the createMessageCorrelation method is called in the catch exception block, transaction rollback ?).
Is there another way to achieve this (also give a try to Signal event with no luck)?
Enclosed you will find
- the BPMN file ‘prsu100c_submission’ (main flow)
- the BPMN file ‘prsu100c unexpected submission error handler’ (notify third party service on each retry)
private void notifyRetry(@NonNull final FailingOnLastRetry annotation, @NonNull final ProceedingJoinPoint joinPoint, @NonNull final ContextualException exception, final int retries) {
if (StringUtils.hasText(annotation.onErrorMessageCallback())) {
var signature = (MethodSignature) joinPoint.getSignature();
var logger = LoggerFactory.getLogger(signature.getDeclaringType());
try {
for (var arg : joinPoint.getArgs()) {
if (arg instanceof DelegateExecution) {
var execution = (DelegateExecution) arg;
RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService();
logger.debug("error while processing activity [{}], create message correlation : message [{}], key [{}], error message [{}], remaining_retries [{}]", execution.getCurrentActivityName(), annotation.onErrorMessageCallback(), execution.getProcessBusinessKey(), exception.getMessage(), retries);
runtimeService.createMessageCorrelation(annotation.onErrorMessageCallback().trim())
.processInstanceBusinessKey(execution.getProcessBusinessKey())
.setVariable(CamundaConstants.VAR_REMAINING_RETRIES, retries)
.setVariable(CamundaConstants.VAR_EXCEPTION, exception.toString())
.correlate();
}
}
} catch (Exception e) {
String exceptionText = "cannot create message correlation";
var exceptionContext = new LinkedHashMap<String, String>();
exceptionContext.put("message_name", annotation.onErrorMessageCallback());
logger.error(new BPMException(exceptionText, e, exceptionContext).toString());
}
}
}
Spring boot : 2.6.11
Camunda : 7.16.0
Regards
Grégory
prsu100c_submission.bpmn (29.9 KB)
prsu100c_unexpected_submission_error.bpmn (3.3 KB)