Wednesday, October 10, 2012

Compensation Hello World

There were several questions about compensation after the Effective Fault Handling in SOA Suite 11g session that Guido Schmutz and I presented at Oracle OpenWorld last week. The presentation included a live demo that showed how compensation can be used to undo previously executed actions in processes and services that are implemented in SOA Suite. Based on the questions, this blog explains the concepts of compensation, gives you an overview of the demo, and provides a download link to the JDeveloper demo project so you can play around with the demo yourself.


Process and service activities can be divided into unit-of-works, called transactions that are either executed (i.e. committed) as a whole or undone as a whole (i.e. rollbacked) due to some error or an explicit rollback command. When the activities within the same unit-of-work span multiple resources (databases, Java components, JMS topics, and so on) these resources all need to support global (XA) transactions and need to enlist in the global transaction, to support commits and rollbacks on the transaction as a whole.

It is not always possible to use transactions as a means to commit, or rollback related activities as a whole. For example when the invoked services do not support global transactions. Next to this, long running processes execute several (implicit) commits since transactions shouldn't be kept open too long: this degrades performance and causes completed activities to remain invisible to others. Once a commit has been executed, the committed activities cannot be rollbacked. Consider an Order-to-Process in which we book the customer's credit card in advance and deliver the ordered goods a few days later. The process will dehydrate at some point causing a commit on the active transaction. If delivery of the ordered goods fails we cannot rollback the credit card booking.

Compensation provides a mechanism to undo already committed activities by means of invoking opposite activities (i.e. compensation) in reverse order. For example booking the opposite amount of money to the credit card that was initially charged. SOA Suite provides the following activities to support compensation:

  • Compensation handler. Compensation handlers contain the activities that need to be executed as part of the compensation flow. These handlers are defined per scope, similar to catch blocks. Per scope you need decide if you need a compensation handler. 
  • Compensate activity. The activity that triggers compensation for a SOA Composite. Executing this activity will cause the invocation of compensation handlers for all successfully completed scopes that have defined a handler, and are not yet compensated. Only compensation handlers of scopes that are directly enclosed by the scope that contains the compensate activity will be executed. The handlers are executed in reverse order, so the handler of the last completed scope is executed first. 
Before we jump to the demo some considerations when using compensation:
  • Compensate activities can only be executed from catch blocks and compensation handlers.
  • Compensation activities either trigger compensation for all enclosed and completed scopes using the compensate activity (supported in BPEL 1.1 and 2.0), or can trigger compensation for one specific scope using the compensateScope activity (only BPEL 2.0).
  • Compensation handlers can only be defined on scope level, not on sequence level.


The demo consists of a SOA composite that implements a simplified Order-to-Cash process. The composite contains a single, asynchronous BPEL component called CompensationExample. After receiving the input message the process executes the following scopes and sequences:

  • Scope Register_Order. This scope simulates the registration of the new order using an Empty activity called Dummy_Register_Order. The scope defines a compensation handler that simulates an undo activity by updating the order with a new status (e.g. cancelled).
  • Scope Invoke_CreditCardService. This scope simulates the registration of the new order using an Empty activity called Dummy_Book_CreditCard. The scope defines a compensation handler that simulates an undo activity by charging the opposite amount to the credit card.
  • Sequence Throw_Fault. This sequence is added for demonstration purposes and throws a fault in case "compensate" is passed as input to the SOA composite; otherwise the process will complete normally. The fault is caught by the Catch_All sequence.
  • Sequence Catch_All. This sequence includes a Wait activity before triggering compensation using a Compensate activity. The wait enables you to inspect the process instance in Enterprise Manager before the compensation logic is executed. After the compensation is completed, the process will send a callback message to the client indicating a fault occurred for this process instance.

Process flow of the Compensation Hello World example

After the wait has finished the compensation handler of the Invoke_CreditCardService is executed. Finally, the compensation of the Register_Order scope is executed. Again, by including Wait activities you can inspect the sequence of events in Enterprise Manager.

The flow of events is shown in the following figures:

Process instance after fault is thrown, but before compensation is triggered
Process instance after compensation is triggered and the compensation handler for the Invoke_CreditCard_Scope is completed. The compensation handler for the  Register_Order scope is still active.
Process instance after all compensation handlers have been executed.
Process instance after compensation has finished and the callback message has been send to the client invoking the process.


You can download the JDeveloper project for the Compensation Hello World example here.


In real-life projects you wouldn't add Throw activities to your SOA composites to trigger compensation and test your compensation logic. In such cases you can best use the out-of-the-box SOA Suite Test Framework and BPEL Test Framework to simulate errors (e.g. unreachable services) in unit tests to inspect and test the compensation logic of your SOA composites.

Wednesday, October 3, 2012

Presentations at OpenWorld 2012

This blog contains a wrap up of our presentations at OpenWorld 2012.

Oracle Fusion Middleware Live Application Development (UGF10464)

In this three hour show moderated by Duncan Mills and Chris Muir, the audience could experience the dynamics between three different teams that are building an application based on Oracle Fusion Middleware:

  1. User Interface in ADF;
  2. Services in SOA Suite and Oracle Database; 
  3. Business processes in BPM Suite.

Behind the scenes at the presentation

It's the fourth time Vennster participated in the Live FMW Development sessions after appearances at ODTUG Kaleidoscope, UKOUG, and OBUG. For OpenWorld 2012 the team that prepared the application consisted of Lucas Jellema, Luc Bors, Aino Andriessen, Guido Schmutz, Lonneke Dikmans, and Ronald van Luttikhuizen. This time we tried a different approach in which we pre-built the application and focused on explaining and demoing it in the first part of the session. After that we made several changes and deployed the improved software components.

Some best-practices the team discussed:

  • Use Business Rules to allow for runtime modification of fast changing business logic instead of design time modifications and redeployment of services. Encapsulate useful Business Rules as separate services instead of adding them to existing SCA composites.
  • Include a heartbeat operation for every Web Service (e.g. by using the Mediator's Echo activity) so you can verify that all technical layers of the Web Service work without triggering a functional side effect. 
  • Invoke PL/SQL from DB Adapters instead of directly executing CRUD operations for additional decoupling.
  • Decouple components and introduce additional reliability and robustness by using events.

Effective fault handling in SOA Suite 11g (CON4832)

In this co-presentation with Guido Schmutz we explored how the out-of-the-box frameworks, patterns, and tools that are available in Oracle Service Bus and Oracle SOA Suite can help you to implement fault prevention and handling capabilities.

360 view during the Fault Handling presentation

The session was pretty well attended, and with an extended Q&A sessions at the end. I never had so many questions after a presentation; don't know if that's a compliment or not ;-) Some of the questions raised:

  • Wrapping asynchronous message exchanges as synchronous exchanges and vice versa. 
  • Where to execute long-running and statefull processes: SOA Suite rather than OSB.
  • Fault handling in fire-and-forget message exchanges: if there's no callback, implement fault handling in the service that is being called.
  • Can the Fault Management Framework of SOA Suite be used to catch internal BPEL faults: use catch activities for that purpose.
  • Transaction boundaries, dehydration points, and global transaction timeouts.
  • Compensation versus rollbacks.
  • Chaining exception policies using the Fault Management Framework.

The slides are available from Slideshare and answer some of these questions. A series of articles is underway that dives deeper into these subjects!

OpenWorld and JavaOne 2012 so far, and we're only halfway!

Not surprisingly the main focus of OpenWorld so far is Cloud and Cloud-related services and products. Oracle is further expanding its Cloud offerings in different areas by means of:

  • Offering IaaS (Infrastructure as as Service) next to PaaS and SaaS;
  • Presenting various of its Cloud products;
  • Announcing the Oracle Private Cloud for organizations that want infrastructure and data to be located on premise, while Oracle supplies and manages the infrastructure as a service. This is useful for organizations that have strict demands for location and control of sensitive data.

There's no escaping Oracle in San Francisco this week

Obviously this focus is not only seen in the big keynotes, but also felt in the various sessions at OpenWorld and JavaOne. For example with the announcement of the new "Pluggable" Oracle 12c Database that is engineered with multi-tenancy in mind. Another example is the excellent presentation that Doug Clarke gave at JavaOne today on the capabilities of EclipseLink. EclipseLink supports different multi-tenancy models: shared or dedicated applications integrating with shared or dedicated databases.

Bob Rhubart in the OTN lounge before the map showing OTN community member nationalities from all around the world

So how about Vennster's involvement in OpenWorld and JavaOne so far this year? Among others, we attended the ACE Director Briefing, participated in the Fusion Middleware Partner Advisory Council, hooked up with the SOA and BPM community, and will participate in an Oracle Technology Network vidcast by Bob Rhubart. We also presented several sessions of which you can read more in upcoming blogs.

Ronald interviewed at OpenWorld