Invoking web services in parallel

In cases where the invocation of web services is not interdependent, we can invoke web services in parallel. The parallel invocation shortens the BPEL process execution time. In this recipe, we will show you how to invoke web services in parallel.

Getting ready

For this recipe we will consume two web services. We will check for the hotel room and car availability in parallel. The availability data will give us information on hotels, where the rooms are available, and a car that is available for the date range. In order to complete the recipe, we need to deploy BookHotelService and BookCarService. The procedure for deploying web services can be taken from the Implementing web services with Axis2 recipe.

How to do it…

The following steps will cover the necessary activities to design the BPEL process for the parallel web service invocation:

  1. We start by creating the SOA composite. We add two web service references and wire them to the BPEL process as shown in the following screenshot:
    How to do it…
  2. We start modeling the BPEL process by assigning the parameters for the web service calls. In the assign activity, we map the input parameters to the web service's input parameters as follows:
    <assign name = "AssignData">
      <copy>
        <from variable = "inputVariable" part="payload" query = "/client:process/client:from"/>
        <to variable = "InvokeHotelSrvc_availableHotels_InputVariable" part = "parameters" query = "/ns2:availableHotels/from"/>
      </copy>
      <copy>
        <from variable = "inputVariable" part = "payload" query = "/client:process/client:to"/>
        <to variable = "InvokeHotelSrvc_availableHotels_InputVariable" part = "parameters" query = "/ns2:availableHotels/to"/>
      </copy>
      <copy>
        <from variable = "inputVariable" part = "payload" query = "/client:process/client:from"/>
        <to variable = "InvokeCarSrvc_getAvailableCar_InputVariable" part = "parameters" query = "/ns1:getAvailableCar/ns1:from"/>
      </copy>
      <copy>
        <from variable = "inputVariable" part = "payload" query = "/client:process/client:to"/>
        <to variable = "InvokeCarSrvc_getAvailableCar_InputVariable" part = "parameters" query = "/ns1:getAvailableCar/ns1:to"/>
      </copy>
    </assign>
  3. Next, we include the <flow> activity that enables the parallel processing. Inside the <flow> activity we add two <invoke> activities for the web service calls as shown in the following screenshot:
    How to do it…
  4. We use the <assign> activity for mapping the results to the output variable as follows:
    <assign name = "Result">
      <copy>
        <from expression = "concat(string(bpws:getVariableData('InvokeHotelSrvc_availableHotels_OutputVariable','parameters','/ns2:availableHotelsResponse/hotels')), '  ',  bpws:getVariableData('InvokeCarSrvc_getAvailableCar_OutputVariable',
                  'parameters','/ns1:getAvailableCarResponse/ns1:return'))"/>
        <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:result"/>
      </copy>
    </assign>
  5. We continue the recipe by deploying the BPEL process to the BPEL server and test it via the Oracle Enterprise Management Console. The test request dialog for the BPEL process is shown in the following screenshot:
    How to do it…
  6. In the response window of the test client we receive the following text:
    How to do it…
  7. In the excerpt of the Audit Trail of the BPEL process, we see that two web services were invoked in parallel. They were invoked at the same time, as shown in the following screenshot:
    How to do it…

How it works…

The BPEL specification provides the <flow> activity for the purpose of concurrency and synchronization. If there is a need to invoke web services in parallel, then we should use the <flow> activity. The activity also ensures that all web services provide a reply before continuing the BPEL process.

There's more…

It is possible to combine sequence and parallel execution of web services. We can bring the sequential execution into the parallel execution, and vice versa. We will show on the abstract layer how a mix of sequential and parallel processing is achieved.

Let's take our recipe and extend it with a requirement that, when we receive information about the hotel and car, we would like to confirm the reservation. We omit the details from the code and leave only the activities. The BPEL process now reads as follows:

<sequence name = "Sequence">
  <flow name = "Flow1">
    <sequence name = "Sequence1">
      <invoke name = "InvokeCarSrvc"/>
    </sequence>
    <sequence name = "Sequence2">
      <invoke name = "InvokeHotelSrvc"/>
    </sequence>
  </flow>
  <invoke name = "InvokeConfirmReservation"/>
</sequence>

We see that the <invoke> activities are nested into the <flow> and <sequence> activities.

See also

  • To explore the sequential invocation of web services in the BPEL process, see the Invoking web service in a sequence recipe
..................Content has been hidden....................

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