Saturday, January 10, 2015

Oracle SOA 12C - Synchronizing the execution of activities within a Flow Activity by using Links


Some times we have to synchronize activities in Flow Activity of  BPEL Process. For example first we have to invoke service A then service B in flow activity. For this kind of behaviour, we have to synchronize the execution of activities within a flow activity to ensure that certain activities only execute after other activities have completed.

Links provide a level of dependency indicating that the activity that is the target of the link (Service B) is only executed if the activity that is the source of the link (Service A) has completed.

Here we see both the scenario with and without Links.


1. Without Links

I have to created two services Hello and Greeting which i will invoke from Flow Activity BPEL process.

Hello Service just return "Hello <Name>" message back to client and Greeting service will return greeting message like "Happy New year".

 HelloWorld BPEL Process



Greeting BPEL Process




  Flow Activity Composite



Flow Activity BPEL Process




As you see above bpel process, it has two bracnhes in flow acitivity. One branch invoke hello service and other invoke greeting service after 20 seconds.

As per flow activity behaviour, it excutes sequencely in same thread. It means that greeting service branch execute first then hello service. As Greeting service wait for 10 seconds, execution of hello service branch started immediately. In this case  hello service branch completed first then hello service.

Input payload for this process is

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ex="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="DataRequest">
    <xsd:complexType>
     <xsd:sequence>
        <xsd:element name="names" type="ex:nameType" minOccurs="1" maxOccurs="unbounded"/>
     </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="nameType">
   <xsd:sequence>
      <xsd:element name="name" type="xsd:string" />
   </xsd:sequence>
  </xsd:complexType>
 
 
   <xsd:element name="DataResponse">
    <xsd:complexType>
     <xsd:sequence>
        <xsd:element name="output" type="xsd:string"/>
     </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>



In our testing we send two "name" records, one will go to greeting service and other one to hello service.








Greeting service



Hello Service




 Audit trail



As you can see in audit trail, greeting service branch still waiting but hello service branch finishes before that.

After 20 seconds greeting service completed.



Now if want to execute greeting service branch first then hello service, we have to use link.

Create a Link in flow activity by double clicking it. Give it name like Flow 1 and click on green plus sign. Name it as GreetingService_To_HelloService




No we have to choose our source and and target. We wan to execute greting service first then our source is Greeting service and our target is Hello service.

Double click on greeting invoke activity and choose source tab. Click green plus sign and choose the link in our case it is GreetingService_To_HelloService link. Keep "Transition Condition " field empty.




Now double click on hello service invoke activity and select source tab. Click on  green plus sign and choose  GreetingService_To_HelloService link.










Now  test this service again












 
As you can see, this time hello service invocation did not happen, only assign activity executed. It's waiting for greeting service invocation to complete first.

So, in this way we can synchronize the execution of activities within a flow activity.