- BPEL and Java Cookbook
- Jurij Laznik
- 505字
- 2021-08-06 16:58:20
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:
- 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:
- 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>
- 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: - 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>
- 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:
- In the response window of the test client we receive the following text:
- 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 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
- 鴻蒙生態:開啟萬物互聯的智慧新時代
- 開源安全運維平臺OSSIM疑難解析:入門篇
- 構建可擴展分布式系統:方法與實踐
- 嵌入式應用程序設計綜合教程(微課版)
- 嵌入式Linux驅動程序和系統開發實例精講
- 新手學電腦從入門到精通(Windows 10+Office 2016版)
- Java EE 8 Design Patterns and Best Practices
- 嵌入式實時操作系統μC/OS原理與實踐
- Joomla! 3 Template Essentials
- AWS Development Essentials
- 從實踐中學習Kali Linux無線網絡滲透測試
- RHCSARHCE 紅帽Linux認證學習指南(第7版)EX200 & EX300
- Red Hat Enterprise Linux 6.4網絡操作系統詳解
- 統信UOS應用開發進階教程
- OpenVZ Essentials