Friday, March 07, 2014

SOA - Handle timeout in a synchronous BPEL processes with Correlation Sets

Recently, I worked on a project and need to handle webservice call time-out issue. In current solution, the developers used JMS Queue to handle the time-out issue. The flow can be described as the following steps.

  1. When our webservice gets a request from client, the message will be put in the request queue
  2. a MDB picks the message and initializes an webservice call to an scheduling system to make an appointment
  3. After the MDB gets the response, it puts the response message into response queue.
  4. The caller  process picks up the message and returns to client.
That the happy path, but sometimes you will need a long time to get the response back caused by the slow network or the busy scheduling system. As the client can't wait for too long and the socket connection has been closed when the response comes back. At this time, the response message will sit in the response queue. When it gets expired, it will be moved to an error queue. The Error handling MDB will initialize a call to the scheduling system to cancel the booked appointment.

Now, we prepared to move the application from WLI to SOA Suite and were asked to handle the same issue in SOA Suite. What I thought is there are 2 approaches to do it.

  1. Implement the exact same logic with BPEL and JMS Queue.
  2. Implement a much smarter process to return the response to client utilizing the BPEL correlation.

I did some research on the internet and didn't get a happy answer on how to implement second solution. But theoretically, I thought BPEL should be able to complete this job as it is statful and supports long run transaction. I didn't give up and kept to look for any sample I could find on the internet and books. Eventually, I found some helpful information from Oracle SOA Suite 11g Developers Cookbook and a blog on AMIS Technology Blog, which are listed in the references. Based on these pieces information, I began my adventure.

At the beginning, I just followed the book as the book mentioned the correlation implementation is different from SOA Suite and didn't looked at the log in detail. I copied the schema and wsdl from the sample code of Oracle SOA Suite 11g Developers Cookbook, then modified them to add an response for the service.  But the code didn't work when I completed and it could not accept any further call with the OnMessage activity.

Later, I began to look at the blog line by line and tried to find useful information. Fortunately, it is really helpful and I found I need to add correlation on the response too. After that, it still didn't work. Then I added an reply before the invocation of third part webservice. Woo! What a magic it is. it worked eventually.

Use BPEL Correlation Sets for repeated (synchronous) access to long running BPEL processes
Chapter 5 of Oracle SOA Suite 11g Developers Cookbook (P96)

No comments: