Step 2 - Creating the Asynchronous Process
If the loan approval process involves another process, in which the response takes too long to respond, you can use an Asynchronous Process to implement it. This allows you to continue the rest of the process flow without waiting for the response.
Let's get started! Follow the instructions in the below sections to complete the BPEL Workflow you created in Step1 with the As ynchronous Process as shown below.
If you did not follow Step 1 - Creating the Synchronous Processes yet, you can import the pre-packaged project of it and continue by following the steps in this Tutorial. Follow the steps below to import it to WSO2 Integration Studio.
- Open the WSO2 Integration Studio, click File, and click Import.Â
- Expand the WSO2 category and select Existing WSO2 Projects into workspace, click Next and upload the pre-packaged project.Â
Adding the Sequence element
- Open the WSO2 EI Integration Studio.
- Right click on the replyOutput element, click Insert Before and click Sequence.
Configuring the InvokeLoanService element
- Right click on the Sequence element, click Add and click Invoke.
- Click on the Invoke element you added inside the Sequence element, and enter InvokeLoanService as the Name in the Description section of the Properties tab.
Adding the Partner Link
- Click on the InvokeLoanService element, click the drop-down arrow of Partner Link  and select Create Global Partner Link.  in the Details  section of the Properties tab.
- Enter LoanPL as the Partner Link Name and click OK .
- Select From Project as the type of the Partner Link, select LoanServicePT  in the Matches field and click OK .
- Click OK in the message, which pops up next to set the prefix of the namespace.
Adding the Partner Role
Select the LoanServiceRole partner role and click OK .
You need to invoke the
getLoanOffer
process. Therefore, this selects theLoanServiceRole
, which includes thegetLoanOffer
operation.
Adding the Operation
Once the partner link is created, double click on the getLoanOffer operation from the Quick Pick view. This automatically updates the input request.
This will auto update the input/output of the Invoke step and creates the following variable.
Configuring the ReceiveLoanOffer element
Right click on the Sequence element, click Add and click Receive.
This creates a new Receive element to capture the result of the LoanService whenever it is sent back to the BPEL process.
- Click on the Receive element you added inside the Sequence element, and enter ReceiveLoanOffer as the Name in the Description section of the Properties tab.
Â
Adding the Partner Role
You need to use the OnLoanOffer operation of the LoanServiceCallBackPortType partner role for the ReceiveLoanOffer element. Therefore, follow the steps below to use the LoanPL partner link you created before for this ReceiveLoanOffer element as well.
- In the Outline tab of WSO2 Integration Studio, click LoanPL under Partner Links.
- Select the following values in the Details section of the Properties tab.
- My Role:
LoanServiceClientRole
- Partner Role:Â
LoanServiceRole
- My Operations:
onLoanOffer
- Partner Operations:
getLoanOffer
- My Role:
Adding the Partner Link
- Click on the ReceiveLoanOffer element, click the drop-down arrow of Partner Link and select LoanPL in the Details section of the Properties tab.
Adding the Operation
Keep your cursor on the Operation  field and double-click on onLoanOffer.
This creates an input of the
getLoanOfferResponse
message type. You can find it in the Variables panel.
This creates the LoanPLRequest1  variable.
Double click on the LoanPLRequest1  variable and rename it to LoanPLResponse.
This LoanPLResponse variable is the response from the LoanService to the BPEL process.
Configuring the Assign2 element
Right click on the Sequence element, click Insert Before and click Assign, to add the Assign2 element.
Mapping the variables
You need to map the required data received from the BankLoanProcessRequest
 message to the LoanPLRequest
 similar to the mapping you did before. Follow the steps below to do this.
Click on the Assign2 element and click New in the Details section of the Properties tab.
- In the From box, expand the input :  BankLoanProcessRequestMessage and select payload : LoanRequest.Â
Â
- In the  To  box, expand the LoanPLRequest :   getLoanOfferRequest and select part : LoanRequest. Â
Â
- Press Ctrl+S to save your artifacts.
- Click Yes in the message, which pops up to initialize the variables.  Â
Â
Follow the steps below to match the other variables.
This creates variable to variable options to map each part of the
CustomerInfo
input (CustomerInfo:CustomerInfoType
) to the corresponding part ofCustomerPLRequest
(part:CustomerInfo
).- Click New and select input: BankLoanProcessRequestMessage → payload : LoanRequest → CustomerInfo : CustomerInfo Type in the From  box and select LoanPLRequest :   getLoanOfferRequest → part :   LoanRequest → CustomerInfo : CustomerInfo Type  in the To  box.
Â
- Press Ctrl+S to save the artifacts.
- Click New and select input: BankLoanProcessRequestMessage → payload : LoanRequest → CustomerInfo : CustomerInfo Type → Name : string in the From  box and select LoanPLRequest :   getLoanOfferRequest → part :   LoanRequest → CustomerInfo : CustomerInfo Type → Name : string   in the To  box.
Â
- Press Ctrl+S to save the artifacts.
- Click New and select input: BankLoanProcessRequestMessage → payload : LoanRequest → CustomerInfo : CustomerInfo Type → Email : string in the From  box and select LoanPLRequest :   getLoanOfferRequest → part :   LoanRequest → CustomerInfo : CustomerInfo Type → Email : string   in the To  box.
Â
- Press Ctrl+S to save the artifacts.
- Click New and select input: BankLoanProcessRequestMessage → payload : LoanRequest → CustomerInfo : CustomerInfo Type → CustomerID : CustomerIDType in the From  box and select LoanPLRequest :   getLoanOfferRequest → part :   LoanRequest → CustomerInfo : CustomerInfo Type → CustomerID : CustomerIDType   in the To  box.
Â
- Press Ctrl+S to save the artifacts.
- Click New and select input: BankLoanProcessRequestMessage → payload : LoanRequest → CustomerInfo : CustomerInfo Type → CreditRating : int in the From  box and select LoanPLRequest :   getLoanOfferRequest → part :   LoanRequest → CustomerInfo : CustomerInfo Type → CreditRating : int   in the To  box.
- Press Ctrl+S to save the artifacts.
- Click New and select input: BankLoanProcessRequestMessage → payload : LoanRequest → CustomerInfo : CustomerInfo Type in the From  box and select LoanPLRequest :   getLoanOfferRequest → part :   LoanRequest → CustomerInfo : CustomerInfo Type  in the To  box.
Configuring the Assign3 element
Follow the steps below to assign the values of the LoanPLResponse to the final output variable of the BPEL process.
- Right click on the Sequence element, click Add and click Assign.
Â
Mapping the variables
- Click on the Assign3 element and click New in the Details section of the Properties tab .
- In the From  box, expand the LoanPLResponse : getLoanOfferResponse and select part : LoanOffer.Â
- In the To box, expand the output : BankLoanProcessResponseMessage and select payload : LoanOffer.Â
- Press Ctrl+S to save your artifacts.
- Click Yes in the message, which pops up to initialize the variables. Â
Follow the steps below to map the other variables.
This creates variable to variable options to map each part of theÂ
LoanPLResponse
 input (i.e., LoanPLResponse : getLoanOfferResponse ) to the corresponding part ofÂLoanOffer
 (i.e., payload : LoanOffer ).- Click New and select LoanPLResponse : getLoanOfferResponse  → part : LoanOffer → ProviderName : string in the From box and select output : BankLoanProcessResponseMessage  → payload :   LoanOffer → ProviderName : string  in the To box.
- Press Ctrl+S to save your artifacts.
- Click New  and select LoanPLResponse : getLoanOfferResponse  → part : LoanOffer → approved : boolean in the From box and select output : BankLoanProcessResponseMessage  → payload :   LoanOffer → approved : boolean  in the To box.
- Press Ctrl+S  to save your artifacts.
- Click New  and select LoanPLResponse : getLoanOfferResponse  → part : LoanOffer → AnualInterestRate : decimal in the  From box and select output :    BankLoanProcessResponseMessage  → payload :   LoanOffer → AnualInterestRate : decimal  in the To box.
- Press Ctrl+S to save your artifacts.
- Click New  and select Expression from the drop down in the From box, and type true().
- Press Ctrl+S  to save your artifacts.
- Click New and select output : BankLoanProcessResponseMessage  → payload : LoanOffer → selected : boolean in the  To box.
- Click New and select LoanPLResponse : getLoanOfferResponse  → part : LoanOffer → ProviderName : string in the From box and select output : BankLoanProcessResponseMessage  → payload :   LoanOffer → ProviderName : string  in the To box.
Configuring the replyOutput element
Click on the replyOutput element and select client as the Partner Link in the Details section of the Properties tab.
- Select process  as the Operation in the  Details  section of the Properties  tab.
- Double click process  in the Quick Pick  section to generate the input and output variables for this element.
- Press Ctrl+S to save the artifacts and their configurations.
After creating all the artifacts, you view the Design View of the BPEL Workflow as shown below.
Every Asynchronous Process requires a Correlation Set. Therefore, next, let's create a Correlation Set for the As ynchronous Processes  you created above. For instructions, see Step 3 - Creating the Correlation Set .