Using dynamic Split-Join to perform work in parallel

In this recipe, we will use the Split-Join functionality of the Oracle Service Bus to handle outgoing service callouts in parallel instead of the usually used sequential method.

Using dynamic Split-Join to perform work in parallel

Getting ready

You can import the OSB project containing the base setup for this recipe into Eclipse OEPE from chapter-9getting-readyusing-dynamic-split-join.

Start the soapUI mock service simulating the Address Checking Service by double-clicking on start-AddressCheckingService.cmd in the chapter-9getting-readymisc folder.

How to do it...

A Split-Join is a separate artifact, which we will create first. In Eclipse OEPE, perform the following steps:

  1. Create an additional folder flow in the project using-dynamic-split-join.
  2. Right-click on flow and select New | Split-Join.
  3. Enter SplitJoin into the File name field and click Next.
  4. Navigate to the operation: StoreCustomer node of the CustomerManagement.wsdl file and click Finish.
  5. The SplitJoin flow artifact will be shown in the detail window.
  6. Drag a For Each operation from the Flow Control section of the Design Palette to the flow between Receive and Reply.
    How to do it...
  7. On the Properties tab of the For Each operation, click <Counter Name> and enter counter into the Counter Variable Name field on the pop-up window. Click OK.
  8. Enter number(1) into the Start Counter Value field.
  9. Enter count($request.parameters/Customer/cus:Addresses/cus:Address) into the Final Counter Value field.
    How to do it...
  10. Drag an Invoke Service operation from the Communication section of the Design Palette into the For Each operation.
  11. On the Properties tab of the Invoke Service operation, click Browse and select the operation: CheckAddress node from the AddressChecking business service in the business folder.
  12. Click OK.
  13. Navigate to the Input Variable tab and select the Create Message Variable item of the Message Variable drop-down listbox.
  14. Enter addressCheckRequest into the Name field and click OK.
  15. Navigate to the Output Variable tab and select the Create Message Variable item of the Message Variable drop-down listbox.
  16. Enter addressCheckResponse into the Name field and click OK.
  17. Drag an Assign operation from the Assign Operations section of the Design Palette and drop it before the Invoke Service operation.
  18. On the Properties tab of the Assign, select addressCheckRequest.parameters from the Variable drop-down listbox.
  19. Click on <Expression> and enter the following XML fragment into the Expression field:
    <add:CheckAddress 
      xmlns:add="http://www.osbcookbook.org/AddressCheckingService/">
    {$request.parameters/Customer/cus:Addresses/cus:Address[$counter]}
    </add:CheckAddress>
  20. Click OK.
  21. Drag an Assign operation from the Assign Operations section of the Design Palette and drop it after the Invoke Service operation.
    How to do it...
  22. On the Properties tab of the Assign, select response.parameters from the Variable drop-down listbox.
  23. Click on <Expression> and enter the following XML fragment into the Expression field:
    <out>COMPLETED</out>

    We have successfully created the Split-Join flow artifact. Now, let's create the business service, which will invoke the Split-Joint through the flow transport. The business service can easily be generated by performing the following steps in Eclipse OEPE:

  24. Right-click on the SplitJoin.flow artifact and select Oracle Service Bus | Generate Business Service.
  25. Select the business folder in the Service Location tree and enter SplitJoin into the Service Name field and click OK.

    Now, let's add the call of the business service to the already existing SplitJoinInvoker proxy service. In Eclipse OEPE, perform the following steps:

  26. Open the SplitJoinInvoker proxy service and navigate to the Message Flow tab.
  27. Insert a Route node into the StoreCustomer branch and name it InvokeSplitJoinRoute.
  28. Insert a Routing action into the Route node.
  29. On the Properties tab of the Routing action, click Browse and select the SplitJoin business service. Click OK.
  30. Select the StoreCustomer operation from the Invoking drop-down listbox.
  31. Deploy the project to the OSB server.

    Now, we can test the proxy service. In the Service Bus console, perform the following steps:

  32. In the Project Explorer navigate to proxy folder inside the using-dynamic-split-join project.
  33. Click on the Launch Test Console icon of the SplitJoinInvoker proxy service.
  34. Select the StoreCustomer operation from the Available Operations drop-down listbox.
  35. Enter a message with two addresses into the Payload field as shown in the following screenshot:
    How to do it...
  36. Click on Execute.
  37. It should not take more than four seconds until the Test console response window is shown (each single Address Checking Service call is taking four seconds to answer).
  38. Click Back to retest.
  39. Enter a message with four addresses into the Payload field and click Execute.
  40. It should still take about four seconds until the response window is shown. The four calls to the Address Checking Service are done in parallel.

How it works...

We have seen how the OSB's advanced mediation feature, called Split-Join, can help to improve the performance of the service by concurrently processing individual parts of a message. The Split-Join first splits the input message payload into submessages (split), processes these submessages concurrently and then aggregates the responses into one return message (join). In our case, the splitting has been done on the collection of addresses in the customer request message and the concurrent processing involves the invocation of the Address Checking Service in parallel.

Split-Joins are useful for optimizing the overall response time when parts of the request messages need to be processed by slower services, that is, each individual address has to be handled by a call to the Address Checking Service, taking four seconds to respond. Because of the parallel nature, the whole Split-Join finishes in little more than four seconds. This is a huge benefit compared to the solution with the For Each action shown in the Using the For Each action to process a collection recipe.

The Split-Join of the Oracle Service Bus comes in two flavors:

  • Static Split-Join branches from the main execution thread of the OSB message flow by splitting the payload into a fixed number of branches according to the configuration of the Split-Join at design time.
  • Dynamic Split-Join branches from the main execution thread of the OSB message flow by dynamically creating new branches according to the contents of the incoming payload. Conditional logic is used to determine the number of branches at runtime.

In this recipe, we have used the dynamic Split-Join.

See also

Check the Using the For Each action to process a collection recipe to see how the processing of the addresses can be done sequentially inside the OSB message flow using a For Each action.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset