Wednesday, October 5, 2011

Implement Parallel Split Join OSB

Example for implementing parallel Split Join in Oracle Service Bus (OSB) 11g:

Consider the following is the scenario:
We have a Customer Inquiry Service, which takes Cust_ID, Cust_name and Brand as an Input and return Cust_ID, Cust_name and Balance as an output.

You will receive a customer list as an Input, here instead of calling "Customer Inquiry Service" sequential, 
We can use Parallel Split Join In OSB to make the parallel call to "Customer Inquiry Service".

The response from all the requests will be aggregated and return back to the client.

Following are the steps:

I created a simple XSD that will take list of customer request and return the list of response.
Request Xsd
Created a simple WSDL based on the request and response element mentioned above





Created a Dummy  "Customer Inquiry Service" proxy service (Customer.proxy) that will return a sample response. Base the proxy service on the WSDL created above. Will call this proxy service parallel. Have purposely used proxy service to demonstrate that split join can be used to call both business and proxy service.  
Sample Response:
<tns:Rs xmlns:tns="http://www.example.org/OrderRq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/OrderRq Customer.xsd ">
  <tns:OrderRes>
    <tns:CustID>101010</tns:CustID>
    <tns:CustName>John</tns:CustName>
    <tns:Bal>1000</tns:Bal>
  </tns:OrderRes>
</tns:Rs>
Now create a new SplitJoin based on the WSDL created above.























You will find the request and response element variable in split join




















Insert the assign action below Receive to initialize the response variable
Eg.
<tns:Rs xmlns:tns="http://www.example.org/OrderRq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/OrderRq Customer.xsd ">
</tns:Rs>
Insert the For Loop, Set the parameter as mention below:-
Parallel : Yes
Name Counter variable: counter
Start Counter: Say Starts with 1 (number(1))
Final Counter: Number Customer in Request count($request.parameters/ord:orderRq)











Create two for loop variables, in this case its Cust_Rq, Cust_Rs

























Now Insert Copy Action to get each customer element from the request and put it in one Variable (Cust_Rq).  Which we will assign as a input of the invoke service.




















Next, Insert the Invoke Action to call the "Customer Inquiry Service" proxt service.
1. Select the Operation mention in the wsdl.
2. Set Input Variable as Cust_Rq
3. Set Response Variable as Cust_Rs
Refer the below screen shot for the same:















This for loop make a multiple calls to the external service and assign the response to Cust_Rs response variable created. Now we have to Insert the contents of Cust_Rs to main Response variable, so that we can aggregate the responses.
Below are the steps for the same.
Add the Insert action after Invoke. 







Now our split Join is ready. Split Join is called from Business service. So let create a Business service now.
Right Click spilt join and click generate business service.




















Now you can call this business service from any proxy and use split join.
Sample test Request:
<ord:Rq xmlns:ord="http://www.example.org/OrderRq">
    <ord:orderRq>
        <ord:CustID>101</ord:CustID>
        <ord:CustName>John</ord:CustName>
        <ord:Brand>Bank</ord:Brand>
    </ord:orderRq>
<ord:orderRq>
        <ord:CustID>102</ord:CustID>
        <ord:CustName>Sam</ord:CustName>
        <ord:Brand>Bank</ord:Brand>
    </ord:orderRq>
</ord:Rq>
Sample Response:
<tns:Rs  xsi:schemaLocation="http://www.example.org/OrderRq Customer.xsd " xmlns:tns="http://www.example.org/OrderRq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<tns:OrderRes>
<tns:CustID>101010</tns:CustID>
<tns:CustName>John</tns:CustName>
<tns:Bal>1000</tns:Bal>
</tns:OrderRes>
<tns:OrderRes>
<tns:CustID>101010</tns:CustID>
<tns:CustName>John</tnsCustName>
<tns:Bal>1000</tns:Bal>
</tns:OrderRes>
</tns:Rs>
Do let me know If you find some problem, Thanks

-Rohan Lopes

11 comments:

  1. how can u log the request to invoke service.(body and the header) ?

    ReplyDelete
  2. You need to use Log action. For logging body your context variable $body and for logging Header use context variable $header.
    Hope this helps.

    ReplyDelete
  3. so you have 2 wsdl's in this right?
    one for getting the actual response(individual response) and other for aggregated response?

    ReplyDelete
  4. HI,

    Just pointing out a correction needed. While creating the for loop variables, select messagetype instead of schemainstancetype. Otherwise it will not be accepted while invoking the proxy service where we can take only messagetype variables.

    ReplyDelete
  5. Yes there can be more than two wsdl's one on proxy side and Individual wsdl's on business side.

    ReplyDelete
  6. I am unable to see the screen shots, can you please send this article to mail id.

    ReplyDelete
    Replies
    1. Veer,
      Thanks for pointing this issue. Have changed the settings, screenshots are visible now.

      Delete
  7. Hi. I'm trying to make this split join, but i can't. Can you send me your code? Please.
    bruno.rgil@ig.com.br

    ReplyDelete
    Replies
    1. Bruno,
      Don't have the code handy, can you tell me what issue you facing?

      Delete
  8. I'm facing some issues and I would like to ask a few questions first. First of all, why do you make use of the prefix 'ref'? Have you declared it somewhere I couldn't find? And I couldn't use the copy function, it gives an error of schema validation.

    ReplyDelete
  9. Free GenericParallel library (a wrapper over Split-Join) will save you hours of work implementing parallel calls in OSB.

    ReplyDelete

Your comments will help improve my posts