Exposing Several Services as a Single Service
In the ESB profile of WSO2 Enterprise Integrator (WSO2 EI), this is commonly referred to as Service Chaining, where several services are integrated based on some business logic and exposed as a single, aggregated service.
In this tutorial, you send a message through the ESB profile to the back-end service using the Call mediator, instead of the Send mediator. Using the Call mediator, you can build a service chaining scenario as it allows you to specify all service invocations one after the other within a single sequence.
You then use the PayloadFactory mediator to take the response from one back-end service and change it to the format that is accepted by the other back-end service.
See the following topics for a description of the concepts that you need to know when creating ESB artifacts:
Before you begin,
Download the product installer from here, and run the installer.
Select and download the relevant EI tooling ZIP file based on your operating system from here and then extract the ZIP file.
The path to this folder will be referred to as<EI_TOOLING>throughout this tutorial.If you did not try the Transforming Message Content tutorial yet, open the WSO2 EI Tooling environment, click File, and then click Import. Next, select Existing WSO2 Projects into workspace under the WSO2 category, click Next and upload the pre-packaged project. This contains the configurations of the Transforming Message Content tutorial so that you do not have to repeat those steps.
Download the MSF4J service from here and copy the JAR file to
<EI_HOME>/wso2/msf4j/deployment/microservicesfolder. The back-end service is now deployed in the MSF4J profile of WSO2 EI. For more information on MSF4J, see the WSO2 MSF4 GitHub Documentation.
Let's get started!
Connecting to the back-end services
Let's create HTTP endpoints to the back-end services that you need to connect, in order to check the channeling fee and to settle the payment.
Right-click SampleServices in the Project Explorer and navigate to New -> Endpoint. Ensure Create a New Endpoint is selected and click Next.
Fill in the information as in the following table:
Click Finish.
Create another endpoint for Settle Payment and fill in the information as in the following table:
Click Finish.
You have now created the additional endpoints that are required for this tutorial.
Creating the deployable artifacts
In EI Tooling, add a Property mediator just after the Get Hospital Property mediator in the in-sequence of the API resource to retrieve and store the card number that is sent in the request payload.
With the Property mediator selected, access the Properties tab and fill in the information as in the following table:
Go to the first case box of the Switch mediator. Add a Property mediator just after the Log mediator to store the value for
uri.var.hospitalvariable that will be used when sending requests to ChannelingFeeEP.
With the Property mediator selected, access the Properties tab and fill in the information as in the following table:
Similarly, add property mediators in the other two case boxes in the Switch mediator. Change only the Value field as follows:
Case 2:
clemencyCase 3:
pinevalley
set property mediator for all cases
Delete the Send mediator by right clicking on the mediator and selecting Delete from Model. Replace this with a Call mediator from the Mediators palette and add GrandOakEP from the Defined Endpoints palette to the empty box adjoining the Call mediator.
Replace the Send mediators in the following two case boxes as well and add ClemencyEP and PineValleyEP to the respective boxes adjoining the Call mediators.
Let's use Property mediators to retrieve and store the values that you get from the response you receive from GrandOakEP, ClemencyEP or PineValleyEP.
Next to the Switch mediator, add a Property mediator to retrieve and store the value sent as
appointmentNumber.add the Get Appointment Number property mediatorWith the Property mediator selected, access the Properties tab and fill in the information as in the following table:
Similarly, add two more Property mediators as follows. They retrieve and store the
doctordetails andpatientdetails respectively, from the response that is received from GrandOakEP, ClemencyEP or PineValleyEP.add the last two property mediatorsAdd a Call mediator and add ChannelingFeeEP from Defined Endpoints palette to the empty box adjoining the Call mediator.
Add a Property mediator adjoining the Call mediator box to retrieve and store the value sent as
actualFee.Access the Property tab of the mediator and fill in the information as in the following table:actual feeLet's use the PayloadFactory mediator to construct the following message payload for the request sent to SettlePaymentEP.
{"appointmentNumber":2, "doctor":{ "name":"thomas collins", "hospital":"grand oak community hospital", "category":"surgery", "availability":"9.00 a.m - 11.00 a.m", "Fee":7000.0 }, "patient":{ "name":"John Doe", "Dob":"1990-03-19", "ssn":"234-23-525", "address":"California", "phone":"8770586755", "email":"johndoe@gmail.com" }, "fee":7000.0, "Confirmed":false, "card_number":"1234567890" }Add a PayloadFactory mediator next to the Property mediator, from the mediators palette to construct the above message payload.
add the payload factory mediatorWith the Payloadfactory mediator selected, access the properties tab of the mediator and fill in the information as in the following table:
We will look at adding the value for the field Args in the following steps.
To add the Args field for the PayloadFactory mediator, click the Browse (...) icon in the Args field. Click on the Add button and enter the following information as in the table below. It provides the argument that defines the actual value of the first variable used in the format definition in the previous step.
Similarly, click Add and add more arguments to define the other variables that are used in the message payload format definition. Use the following as the Value for each of them:
$ctx:doctor_details
$ctx:patient_details
$ctx:actual_fee
$ctx:card_numberAdd a Call mediator and add SettlePaymentEP from Defined Endpoints palette to the empty box adjoining the Call mediator.
Add a Respond mediator to send the response to the client.
You should now have a completed configuration that looks like this:
Save the updated REST API configuration.