Develop your first Integration with WSO2 Micro Integrator

oneIAM
6 min readJun 21, 2023

--

In nutshell WSO2 Micro Integrator is a more lightweight, container friendly version of WSO2 Enterprise Integrator. Why container friendly: It has reduced the up time from 40sec to 4sec, memory requirement from 4GB to 1GB and CPU requirement from 2 core to 0.5 core. Power of WSO2 Micro Integrator is, it supports micro service integrations as well as centralized ESB sort of Integrations. Below 2 diagrams would help you to understand the difference between micro service integrations and centralized integrations. Ref [3].

Microservices Integration

Centralized Integration

Below sample has been extracted from WSO2 documentation to deploy simple integration with just 7 steps.

Step 01: Deploy sample services

Download sample files to deploy sample services from the link [1].

Unzip the the downloaded directory and navigate to Backend directory

Execute below command to run sample services

Java -jar DoctorInfo.jar

Test both services from Postman or any other REST client

GrandOak service

PineValley service

Step 02: Download and Install WSO2 Integration Studio

Download the WSO2 Integration Studio from the link [2].

Install the correct binary as per your operating system. Make sure you provide valid corporate email because download link will be sent your email.

Step 03: Create the Integration

On the landing page of WSO2 Integration Studio, click on New Integration Project

Put ‘Integration Project Name’ as Healthcare and you will see it automatically creates two modules HealthcareConfigs, HealthcareCompositeExporter. At the end click on the Finish button.

Click on HeathcareConfigs → src → synapse-config → endpoints → Endpoint → Create A New Endpoint → Next and add below details.

Endpoint Name: GrandOakEndpoint

Endpoint Type: HTTP Endpoint

URI Template: http://localhost:9090/grandOak/doctors/{uri.var.doctorType}

Method: GET

Continue same steps for ‘Pine Valley Hospital’

Endpoint Name: PineValleyEndpoint

Endpoint Type: HTTP Endpoint

URI Template: http://localhost:9091/pineValley/doctors

Method: POST

Create HealthcareAPI as below

Define resource for the REST API

Url Style: URL_TEMPLATE

Uri Template: /doctor/{doctorType}

Methods: Get

Since the integration has to invoke two backend services parallelly, clone mediator should be added at the beginning of the integration.

Right click on the clone mediator and select Add/Remove Target. Add Target Branches as 2 and you will see two branches from the clone mediator.

Put call mediator in the first branch and put GranOakEndpoint from Defined EndPoints

For the PineValleyEndpoint doctorType parameter has to be sent as the request body so that incoming message has to be transformed in order to send correct values to the backend service. Payload factory mediator is being used here in order to transform messages.

Payload Format: Inline

Media Type: json

Payload: {“doctorType”:”$1”}

Args: $ctx:uri.var.doctorType

In order to add arguments you have to click + icon in the right bottom and follow below steps

Click on ‘Argument Expression’ text box and new pop up window will appear like below

Add the expression and click on Ok and then click on the finish button from PayloadFactoryArgument.

Now mediation logic is ready to put PineValleyEndpoint as well so we can add PineValleyEndpoint with call mediator as it was already done for GrandOakEndpoint.

Since two backend services return responses into MI, aggregate mediator need to be used in order to merge results together.

Click on ‘Aggregation Expression’ text box and you will get a pop up window. Insert expression as given in below screen.

Finally add a Respond mediator to send response back to the client.

End of the integration your source code of the integration should be like below.

Step 04: Test Integration with embedded Micro Integrator in Integration Studio

In order to test the integration within embedded Micro Integrator in Integration Studio, select CompositeExporter → Right Click → Export Project Artifact and Run

Make sure you select all artifacts that need to be deployed.

Once it is deployed, you can see server logs and service end points as in below screen

You can simply test your integration with Postman, which sends aggregated results from both backend services. Please use ‘Ophthalmologist’ as the doctorType.

Step 05: Download and Install WSO2 Micro Integrator

You have already tested your integration with embedded Micro Integrator instance shipped with Integration Studio. Now you can test your integration in the actual Micro Integrator runtime environment. You can download WSO2 Micro Integrator from the link [2].

Unzip the downloaded artifact and run it according to your operating system. Make sure you stop embedded Micro Integrator instance from Integration Studio before you start Micro Integrator.

Step 06: Deploy .car application to Micro Integrator

Right click on HealthcareCompositeExporter → Export Composite Application Project → Select Destination to {poduct_home}/repository/deployment/server/carbonapps

Click on next and make sure you select all artifacts before press finish button in the screen below.

Step 07: Test the Integration with Micro Integrator

Now you can test your Integration running on an actual micro integrator environment.

References

[1] https://apim.docs.wso2.com/en/latest/get-started/integration-quick-start-guide/

[2] https://wso2.com/micro-integrator/#

[3] https://apim.docs.wso2.com/en/latest/integrate/integration-overview/

--

--

oneIAM
oneIAM

Written by oneIAM

One-stop solution for all your enterprise identity and access management requirements

No responses yet