Compensation Events don't appear to be triggered unless a subprocess completes

Newish to BPMN and Camunda.

Compensation Events don’t appear to be triggered unless a subprocess completes. So what is the alternative ?

I have a subprocess with a mix of manual and automated tasks. That subprocess could be “interrupted” at any time by an update, because an update requires re-evaluating a preceding external task.

The automated tasks within the subprocess have side-effects in external systems, which need to be “reverted”. Since we don’t know how many automated tasks within the subprocess were completed, it would make sense that each automated task have a compensation event to “undo” what it did.

The problem is that the conpensation events don’t get fired when the subprocess is interrupted. Apparently, this is expected (although annoying)

So, the question is: How should this be done?

This is an approximation of what I need to deal with:

Hi @Nick-Minutello

You have to trigger the compensation to happen.
Here is an example that tries to show, how it could be done.

The message event in the event subprocess needs to be triggered and that will lead to a compensation. Afterwards the message end event will trigger the message boundary event and the scope will be left and entered again.

Thanks for the advice. Am going to test that now.

In my case, I presume I will need a bunch of throw compensation events - one for each task in my subprocess that needs compensation.

No. A compensation throw event will run the compensation for all activities in the current scope.

Oh, nice! I was under the impression the throw had to be linked to a compensated activity. I just tested and it works. If it is unlinked, it just compensates for all in the current scope - is that it ?

Another question, from your diagram: - is the MessageEnd event sending a message that the Message Boundary event is listening on?

That doesn’t appear to be working for me. The Message Boundary event never gets triggered (the subprocess exits via the normal path). Have I missed a trick?

Yes exactly. If no specific activity is given, it’ll compensate all in the current scope and also you can specify whether to wait for completion.

With the message end event, you have to program a delegate that actually does the correlation of the message. There’s no automatic correlation behind the event.

Otherwise you could use some other type of event (e.g. escalate or error) if that fits for your use case. Those will be linked by the error message or the escalation reference.

Thanks again for the valuable info. Much appreciated.

you have to program a delegate that actually does the correlation of the message

Interesting. Can you give more detail about what you mean?

I tried writing an implementation for the message end event that tries to correlate a message that would trigger the boundary event, but we run into the problem that there is no subscription available for that message.

If I understand correctly, I think it is because the subprocess has ended (we are processing the end event), therefore cannot be interrupted by a boundary event. Not sure if this is correct, but we haven’t been able to make it work.

Any further details would be much appreciated

I would have thought the subscription is still there, even if it’s an end event.
But you could of course also use an intermediate message throw event. That should definitely work.

Use an escalation throw / escalation boundary.

Messages aren’t supposed to be thrown and caught within the same process instance.

Yes, you are right.
It does appear that messages are for communicating between processes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.