Thursday, May 01, 2014

BPEL Compensation Handler - Handle Faults inside a Compensation Handler

Hi,

This was something I would like to post. I had searched about the use of compensation handler and its rollback handling. But nowhere it was mentioned as to how to handle the faults if one occurs inside a compensation handler.
My first thought about this case was "If a fault occurs inside a compensation handler, the compensate activity should get faulted out.". But unfortunately that did not happen or it can be a suggestion to the BPEL developers. So let me brief you about how I used the compensation handler and how I handled the fault when it occurs inside a compensation handler.

USE-CASE :  There were three external APIs provided with their respective rollback APIs. I just need to invoke them using BPEL. If some fault occurs in any one of the APIs during their sequential execution, the rollback APIs of previously-successfully-executed APIs needed to be invoked. If some fault would occur during rolling back, consumer must be informed about it. All this will happen in a synchronous fashion.
Fig. 1: BPEL flow with compensation handler.
Okay so the above picture depicts the flow. Compensation handler works on scopes and can be called in another compensation handler or a catch/catch all block. The advantage of compensation handler over a fault handler is that do not need to have identifiers to identify to which scopes have successfully completed in executions. The compensate activity does that automatically. Please note that by scope I mean the bpel activity which means we put all the concerned activities which are required to complete a unit of work for a process.
As you can see in figure that I have four units of work to be completed to achieve successful execution of my process task. The last unit of work was not required to be in a scope since that being the last unit of work would never need any compensation process for itself. On every unit of work(scopes), I have added compensation handler. Inside each compensation handler I have put all those activities which are required to be performed to compensate the association scope work.
The main part which I have played here is addition of specific catches and a catch all activity over a parent scope. Inside the two catches, I have used the compensate activity. The compensate activity would realize the parent scope to which it is associated. Suppose an error occurs in my fourth unit of work, the fault propagates to any of the catch and compensation would start - that means the control from the bottom would start calling those compensation handlers whose scopes have been successfully executed out to the topmost scope. All these unit of work/scopes should lie with in a parent scope. Now suppose while compensating , the second compensation handler errors out, then I threw a fault other than the faults for which I have associated a catch so that the fault propagates to the CatchAll block. The CatchAll block re-throws it to main scope where it is handled in the manner required by business.


A more simpler example is available at the following link ;

http://soatraining.hpage.com/get_file.php?id=1433816&vnr=683435

No comments:

Post a Comment