Camunda 7 Extension of Compensation Behaviour, Spring Boot Starter

Hi all,

thanks for taking your time reading through this :slight_smile:

For my master thesis, I want to extend some of the Camunda 7 behaviour regarding compensation. In short, I’ve been researching on error handling methods and concepts that support partial compensation.

Two such concepts I want to implement. They are called Savepoint and Alternative Paths.

A savepoint is a process state where compensation can end. It is a highlighted task (like a task type), that when successfully completed, removes the need to execute a global compensation to the beginning of the process model, instead it only needs to compensate to this task.

An alternative path (AP) is a unit of work that is wrapped by two AP gateways. The AP split gateway will trigger the first alternative flow and if an error occurs on this path before reaching the AP join gateway, compensation is executed until the AP split gateway is reached (like a savepoint). Then the second alternative is triggered. This continues until either the AP join gateway is reached without an error or an else-path is taken, which throws an error.

Lastly, I also want to further implement retry tasks, that specify a retry count and a cooldown period for a task, if it fails. I know Camunda retries 3 times by default, hence I probably need to adapt this.

I’ve been recommended to try the following approach:

  1. Set up a new SpringBoot project with Camunda 7 Spring Boot Start
    
  2. Define special activities in BPMN by using [ExtensionElements](https://docs.camunda.org/manual/7.21/user-guide/model-api/bpmn-model-api/extension-elements/)
    
  3. Implement [ActivityBehaviors](https://github.com/camunda/camunda-bpm-platform/tree/master/engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/behavior) for the special task types (also for new gateways)
    
  4. Implement a [ParseListener](https://github.com/camunda/camunda-bpm-examples/blob/83941d97825fdc488bf582cd4b3ae14672dabf9a/process-engine-plugin/bpmn-parse-listener/README.md#create-a-bpmn-parse-listener-implementation) as a ProcessEnginePlugin, which, analogous to [BpmnParse.java](https://github.com/camunda/camunda-bpm-platform/blob/eabe8087b5cb75aa782798910fad0c6100eb5f59/engine/src/main/java/org/camunda/bpm/engine/impl/bpmn/parser/BpmnParse.java#L62), overwrites the Activity Behaviour for the special types
    

So far so good, I’ve been trying myself at the Spring Boot Setup so far.

Still open questions remain and I would appreciate feedback regarding the approach.

My goal is to show that the behaviour I define in the thesis can be executed. I think the simplest solution would be to write unit-tests executing a sample process that then logs the correct execution of the behaviour.

My question:

  1. Can I adapt Camunda behaviour (retry counts, compensation behaviour) with this spring boot approach?
  2. Are there easier ways to implement my approach?
  3. How can I write a Unit Test that deploys a process model and triggers an error in a specific task? I know that I can use Script Tasks to throw errors, is there a better way?
  4. Are there any examples/guides for this approach? For example, the unit testing, adding new behaviour with an element? That could help.

I’m thankful for any pointers and appreciate the time. I can also provide some more detailed behaviour descriptions, which are still work in progress. See for this the PDF here

Thanks in advance!

I’ve found an example for a unit test using Spring Boot here

Hi @SandroSp. :wave:

The approach sounds reasonable. :+1: The example with the external task service is useful.

In the end, we probably build a process engine plugin that adds the new behavior. Then, the plugin can be configured for a process engine, for example, in Spring Boot setup.

However, you don’t need Spring Boot for the plugin. You could use the starter to test the behavior. For testing, a simple JUnit test is fine.

Implementing the new compensation behavior could be tricky. As inspiration have a look at CompensationUtil.java

Enjoy the hacking. :rocket:

I’ve worked a bit with Camunda in Spring Boot, so I might be able to help. You can definitely adapt Camunda’s behavior with your approach, and unit tests are a great way to show it works. To trigger errors in tests, using Script Tasks is one option, but you can also throw errors directly in Java code.