How to trigger the Camunda Retry mechanism in case of a service call

Hi,

I was reading the latest book of Bernd : Practical Process Automation (great book btw)

And there I spotted the following workflow

When I try it myself in my implementation that uses a Java Delegate the “Retry mechanism” only is activated when I throw an java exception, when I throw a BPMN_ERROR then the retry is not performed but the “Error Boundary Event” will directly consume the event and the “Error Cleanup Task” is triggered.

So what am I doing wrong in my setup, I would like to have to have that the java call (JavaDelegate) will retry 5 times with a timespan of 5 min and if then the exception remains the “Error Boundary Event” will trigger then “Error Cleanup”

You might query the current job and check the number of retires left. If it’s zero you throw a BpmnError.

1 Like

You can try a model like this

image

This one I was able to implement but it is one is one of the anti-patterns that is defined on the Camunda website as you putting technical error handling stuff in your business model

Camunda Best Practices - Operating Camunda

So this is what I wanted to avoid

ok then try this

https://docs.camunda.org/manual/7.10/user-guide/process-engine/the-job-executor/#retry-intervals

Hi @Jan_Casteels,

you can access the ExecutionEntity in your delegate code and get the remaining retries from there and finally throw a BpmnError like here:

  public void execute(DelegateExecution execution) throws Exception {
    String content = (String) execution.getVariable("content");
    ExecutionEntity ee = (ExecutionEntity) execution; 
    try {
      publishTweet(content);
    } catch (TwitterException e) {
      if (ee.getJobs().get(0).getRetries() == 0 && e.getErrorCode() == 187) {
        throw new BpmnError("tweetDoppelt", e.getLocalizedMessage());
      } else {
        throw e;
      }
    }
  }

Hope this helps, Ingo

3 Likes

Hello @Ingo_Richtsmeier ,

I didn’t know it’s possible this way, thank you for the hint. BTW: Why is the check for the code 187 needed?

I’d do it via a job query (and search by the activity id). But the idea is the same.

1 Like