soabpelsoa-suite

Oracle BPEL, why compensation while catch can handle exception


I just wonder in Oracle BPEL, the purpose of compensation is business rollback. But catch can do the nearly similar things (except rollback in reverse order of completion). I don't really understand why we still need Compensation?


Solution

  • There are many scenarios in which manual coded compensation in error handlers will be pretty hard if not impossible to write and will contain lots of duplicate code.

    Imagine you have following process:

    <flow>
      <sequence>
        <invoke name="I1"/>
        <invoke name="I2"/>
      </sequence>
      <sequence>
        <invoke name="I3"/>
        <invoke name="I4"/>
      </sequence>
    </flow>
    

    If you want to do compensation handling you just need to add compensation handlers to every invoke and you are done.

    If you went by using the error handlers then you would need to somehow check which activities have already been executed. Imagine I4 throws a fault. You know that I3 has been completed and needs to be compensated. However, you do NOT know whether I1 or I2 has been started nor completed yet. You would need to fiddle around with flags as variables that you need to set on isolated activities etc. Also the error handlers for I2, I3, and I4 would need to contain the compensation logic for I1. Using compensation handlers is much cleaner and easier than trying to re-invent them :)