Home > BPEL, Oracle, SOA > Correlation Set in BPEL to Interrupt BPEL

Correlation Set in BPEL to Interrupt BPEL

Its been quite sometime since I blogged last – got very busy for past few months. Back now with something that I feel interesting.

Use case: A composite instance triggers a BPEL component. The BPEL component may invoke many asynchronous flows or it might be in wait state using “wait” activity or it might use a Human task and wait till human task completes. These scenarios might dehydrate BPEL. In this case, I take a scenario where I want to terminate the BPEL component instance when BPEL process is waiting for some legitimate reason.

Technical solution: The composite exposes a service with two operations. One MainOperation that would initiate the main flow of the BPEL. Two InterruptOperation that would trigger the OnMessage event handler of the same BPEL process and terminate the corresponding component instance initiated through MainOperation using Correlation sets.

Sample app used below: http://kavin-sample-apps.googlecode.com/files/InterruptBPEL.rar

Description of the project:

Create a SOA Application and Project with an empty SOA Composite.

The input schema that I have chosen for this composite is below. This schema has two messages.

1) EmployeeDetails -> Detail sent to initiate the main BPEL flow which has the core business logic. EmployeeId in this message is used in correlation set.

2) InterruptPayload -> This is used by InterruptOperation that is used to terminate the BPEL instance. This also carries EmployeeId so that the main flow can be correlated.

Create a new BPEL Process. Choose Template as “Base on a WSDL” and create a new WSDL file. Choose an one way operation and name it as “EmployeeProcessingFlow”. This is going to be the operation that is going to execute the core business logic in the BPEL process. This operation would be using “EmployeeDetails” element in above schema.

Instead of creating a new composite service for the Interrupt flow, let us add an additional operation to the existing WSDL in the same port. This operation is going to use a newly defined WSDL message “InterruptMessage” that would point to “InterruptPayload” in above given schema.

<wsdl:message name="requestMessage">
<wsdl:part name="EmployeeDetailMessage" element="inp1:EmployeeDetails"/>
</wsdl:message>
<wsdl:message name="InterruptMessage">
<wsdl:part name="InterruptMessage" element="inp1:InterruptPayload"/>
</wsdl:message>
<wsdl:portType name="EmployeeProcessingPort">
<wsdl:operation name="EmployeeProcessingFlow">
<wsdl:input message="tns:requestMessage"/>
</wsdl:operation>
<wsdl:operation name="InterruptFlow">
<wsdl:input message="tns:InterruptMessage"/>
</wsdl:operation>
</wsdl:portType>

Open the newly created BPEL process – “EmployeeProcessingProcess.bpel”. Add an OnMessage Event Handler to the global scope. This branch is going to wait for the incoming request from “InterruptFlow” operation of “EmployeeProcessingService”.

Now let’s correlate the receive and OnMessage entry point of EmployeeProcessingProcess into a single flow using correlation sets. To know more about correlation sets, refer to this section of Oracle SOA Suite Developers Guide. Basically correlation set is a way to attach a business specific key information to a BPEL instance so that the specific instance can be fetched at runtime and process can be executed further.

To start with, edit the receive activity of the BPEL process and add a new Correlation. Create a new Correlation set – “EmployeeFlowCorrelationSet”  with a property to bind the business object specific unique key – BindEmployeeId. Add the EmployeeId element from the Input message of the receive activity as a “Property Alias” for Property. Make sure “Initiate” property of this correlation in this receive activity to “yes”.

Tip: In above screenshot, NOTE that there is no icon to “choose” Query declaratively. So point the cursor there and press Ctrl+Enter so that it would show the message automatically to select.

Add a wait activity after receive and set wait time to 5 minutes to simulate the use case. On OnMessage branch, do a terminate to cancel the BPEL flow. So when the first message comes from “EmployeeProcessingFlow”, the BPEL will be in wait state for 5minutes. In the interim, when message from “InterruptFlow” comes, then it would be correlated with old instance and the instance would be terminated. If certain clean up need to be done before termination, then it can be included in OnMessage branch before Terminate.

Edit the OnMessage branch and bind the same correlation. In this OnMessage branch, the EmployeeId from InterruptMessage has to be set as Property Alias for the existing correlation set.

That completes the coding :-)

Testing the project:

Now deploy the composite to EM and access the end point using the default end point tester URL.

http://localhost:7001/soa-infra/services/default/InterruptBpelFlow/EmployeeProcessingService_ep

Select the operation “EmployeeProcessingFlow” that handles main flow. Enter an EmployeeId value like “349827495″ and a random Salary value and Invoke this to Initiate the composite main flow. This would initiate the BPEL process receive activity by setting EmployeeId as correlation id and put the BPEL in wait state for 5 minutes which can be seen from EM.

Now on the same URL [http://localhost:7001/soa-infra/services/default/InterruptBpelFlow/EmployeeProcessingService_ep], select the “InterruptFlow” operation with same EmployeeId as input so that it would correlate with above mentioned BPEL instance and terminate it.

Thanks for Reading and Keep Smiling :-)

Kavin

  1. February 19, 2012 at 7:45 pm

    So finally you are back :) I was wondering why you did not post anything in recent times. Got the mail alert today about your new post and its again a masterpiece like your older posts. I hope to understand some part of SOA some day by reading your posts.. :)

  2. kumar
    April 20, 2012 at 2:10 pm

    Its good to understand. sir i have a question , how we can give security to the BPEL in soa project?
    CAn u please explain with the Images plzzzz

  3. SJ
    August 4, 2012 at 7:28 pm

    Hi Kavin,
    Nice post.
    I have one doubt, while creating correlation set in the query part. when I press Ctrl + Space it doesn’t come up with XPath building assistant, though it shows “Press Ctrl + Space for invoking XPath Expression builder assistant”. It means I have to write the XPath expression manually. It might create issues sometime, if is by mistake a typo.

    • August 4, 2012 at 8:52 pm

      Can you try typing “/” first and then try “Ctrl+Space”? Which version of jdev are you using? I vaguely recollect that there was some issue in older version where ctrl+space doesn’t work.

  4. SJ
    August 5, 2012 at 9:09 am

    Jdeveloper version 11.1.1.6.0 – seems to be the latest.

  5. SJ
    August 7, 2012 at 11:28 am

    Hi Kavin,
    For understanding the correlation concept, I have developed small demo project. Everything works fine as I understood this concept. But the receive activity which is designed to receive response via callback is in waiting state in the flow diagram & Running state in flow audit trail. I have posted my query on OTN https://forums.oracle.com/forums/thread.jspa?threadID=2423968&tstart=0 describing what I am trying.
    Could you please pour in your thoughts.

  6. santosh
    November 19, 2012 at 6:24 pm

    Hi Kavin,
    This is santosh. Your explanation is really great.
    I find few points in this post.
    1. the example what you provided in link and what you explained in post are different.
    2. the composite you provided in the link is not working as expected.(correlation not working).
    3. in the post as you explained, we have two operations with different messages. You mention one correlationSet for both operations(with receive activity and onMessage ). With this we have messageType miss match exception will occur.
    So please correct these points and provide correct info.

  7. Biswajit
    February 25, 2013 at 2:58 pm

    Hi Kavin,
    Thank you for this simple example . It is really helpful to understand the corelation example . Expect more from you to post these kind of simple examples

  8. Padma
    May 1, 2013 at 10:16 am

    Hi
    it is really very easy to understand

  9. Padma
    May 1, 2013 at 10:17 am

    can u plz tell what XSLT

  10. Kuba
    May 31, 2013 at 2:21 pm

    Hi Kavin – grate article
    I have 2 question for you
    If I send message with wrong correlation id – instance in EM hava Instance State Running and if go into it have state commpleted – is any way to chage Instance status in EM main page to completed
    In your sourcecode is some other example unfortunatly not working – could you check it and udodate it :)
    Regards Kuba

  11. manoj loya
    July 9, 2013 at 12:04 pm

    Can we use correlation sets for onfault handlers for the async service invocations ? We have 3 branches in a Flow activity calling different async operations of the same partnerlink. Now when the fault happens in any of the async , how do correlate to the appropriate onfault branch ? Can we use a command onMessage (fault) at BPEL level without using any correlations sets and achieve the fault handling ?

  12. Mithun
    October 3, 2013 at 10:12 am

    Hello,
    It’s simple & easy to implement and understand

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 53 other followers

%d bloggers like this: