I have probably heard the word "compensation" in the last two months more than I have ever heard it before, which outlines how critical this feature is becoming. Through
this post, David French touched on a very important issue in BPMN/BPEL and compensation support that I am sure our community will find very interesting.
Starting from 5.2, Intalio introduced major improvements in Compensation support whereupon we are able to support any kind of scenarios involving compensation.
The only problem left is, you need to know how to do it! There is a few extra restrictions on the modeling side that when respected, everything becomes clearer and much easier to do.
These restrictions are not a result of non compliance with specifications , it is actually a consequence of incompatibilities between the BPMN and BPEL: Despite all the efforts made by OMG to ensure a smooth translation between those specifications, they still disagree on a certain number of points, among which compensation and error handling.
By the release of 5.3, we are hoping that Intalio will be able to align those specifications more and ease the use of those features on the user end. Meanwhile, users will just have to respect the extra restrictions. Again, this does not go against neither BPMN nor BPEL, it just ensures a better mapping between them. Hence, diagrams and generated BPEL code will still be 100% BPMN and BPEL compliant as you will notice in this thread.
The business case presented by David was both simple and realistic and I would like to make use of the scenario and the diagrams as support material for this discussion. I will go through the diagrams and explain for each why they behaved as such. This will cover the most important parts of compensation and error handling.
First diagram:Problem : Starting a compensation from a normal execution mode . By the BPEL specification, you only compensate when you have an error (kind of makes sense from an execution stand point doesn't it?)
So first rule is: To compensate a scope from a normal mode, throw an error, catch it and then compensate it.In his specific case, he did the "throw" part in the second diagram, and the "catch" part in the last one, but never the "compensate" part. I will go back to that later on.
Second diagram: Problem: compensating a scope that is not immediately enclosed in the scope the compensation is thrown from.
This is also a BPEL rule: you can only compensate a scope from its immediate parent.So the only scope allowed to compensate the "book hotel" scope is the fault handler of the parent scope.
Third diagram: Problem: did not specify a fault handler that describes how he would like to handle the fault in this particular case.
When you don't specify a "Fault Handler" on a scope, BPEL automatically installs what it calls "Default fault handlers". A default fault handler compensates all sub-processes in your scope and rethrows the fault to the parent one.
So when you throw an error, it is a best practice that you catch it and define how you want to handle it.
So in your case, you throw an error in the "book air" sub-process without defining a fault handler. The default fault handler will compensate all the enclosed scopes in the "book air" scope (none in your case") and rethrow the fault to the parent scope.
The parent scope has no fault handler either, so its default fault handler will take care of it. It will compensate all the completed scopes, in your case "book flight" scope only as the "book Air" has not successfully completed, and then it will rethrow the fault to the process scope. Hence the process faults and exists.
Fourth diagram:
Problem: The fault handler is empty .
You are defining a fault handler for the scope, so the default fault handler will be uninstalled. Your fault handler is empty so nothing will happen when this fault is thrown.
The solution:Now I think you all see how the design should be done :
In the fault handler, we should compensate the scope "book air".
Please note that I gave an extensive explanation for what happened
including some technical details that you don't have to be aware of to solve the problem. Just make sure you apply the rule "throw, catch ,compensate" and you will be fine.
I hope this gives a good first insight into compensation and error handling...
Feedback, comments and further questions or additions are more than welcome!
Ihab EL Alami