This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Sending a Simple Message to a Service
Let’s try a simple scenario where a patient makes an inquiry specifying the doctor's specialization(category) to retrieve a list of doctors that match the specialization. The required information is available in a microservice deployed in the MSF4J profile of WSO2 EI. We will configure an API resource in WSO2 Enterprise Integrator (WSO2 EI) that will receive the client request, instead of the client sending messages directly to the back-end service, thereby decoupling the client and the back-end service.
In this tutorial, you will create a REST API in WSO2 Enterprise Integrator to connect to a REST back-end service(microservice) that is defined as an HTTP Endpoint in WSO2 EI. If you want to see how information stored in a database (instead of a microservice) can be used, see the tutorial on sending a simple message to a datasource.
Before you begin,
Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
Download the WSO2 EI ZIP file from here, and then extract the ZIP file.
The path to this folder will be referred to as<EI_HOME> through out this tutorial.Select and download the relevant WSO2 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>through out this tutorial.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.
Let's get started!
This tutorial includes the following sections:
Creating the message mediation artifacts
Requests going through the Enterprise Integrator are called messages, and message mediation is a fundamental part of any ESB. In this section, we will configure message mediation for requests received by the Enterprise Integrator that need to be sent to the Healthcare back-end service. We will use Eclipse-based WSO2 EI Tooling to create the message mediation artifacts and then deploy them to WSO2 EI.
See the following topics for a description of the concepts that you need to know when creating WSO2 EI artifacts:
Creating the deployable artifacts project
In Eclipse, open the Developer Studio dashboard by clicking the Developer Studio menu and choosing Open Dashboard.
Click ESB Solution Project and create a project named SampleServices and select the following check boxes so that the relevant projects will be created.
Create Registry Resources Project
Create Connector Exporter Project
Create Composite Application Project
Click Finish.
You have now created the following projects as shown in the Project Explorer:
Next, inside the SampleServices ESB Config project, we will create an endpoint that will allow the Enterprise Integrator to connect to the back-end service.
Connecting to the back-end service
To connect to the back-end service, we must expose a URL that can be used to connect to the service. To do this, we will create an endpoint for this service.
The sample back-end service (i.e. the Hospital-Service-2.0.0.jar file) we are using in this tutorial is a sample MSF4J service.
Right-click SampleServices in the Project Explorer and navigate to New -> Endpoint.
Ensure Create a New Endpoint is selected and click Next. Give the information as in the table below:
Click Finish.
The QueryDoctorEP endpoint you created is saved in theendpointsfolder within the ESB Config Project you created.
Now that you have created the endpoint for the back-end service, it’s time to create the REST API and the relevant API resource that will receive requests from client applications, mediate them and send them to the endpoint, and return the results to the client.
Mediating requests to the back-end service
We will use WSO2 EI Tooling to create a REST API named HealthcareAPI. We will then create a resource within this API for the GET HTTP method that is used to send requests to the Healthcare back-end service and retrieve available doctor information.
In the Project Explorer, right-click SampleServices and navigate to New -> REST API.
Ensure Create A New API Artifact is selected and click Next.
Fill in the information as in the table below:
Click Finish. Once the API resource is created, the design view of theHealthcareAPI.xmlfile appears so that you can start configuring the API resource.
Click the Resource icon on the left side of the canvas. The properties for the API resource will appear on the Properties tab at the bottom of the window. (If they do not appear, you can right-click the proxy icon and click Show Properties View.)
On the Properties tab provide the following in the Basic property:
Url Style: Click in the Value field, click the down arrow, and then select URI_TEMPLATE from the list
URI-Template: /querydoctor/{category}
This defines request URL format. In this case, the full request URL format is http://<host>:<port>/querydoctor/{category} where {category} is a variable.
In the Methods section of the properties tab, set the value of Get to true. This defines that the API resource created handles only requests where the HTTP method is GET.
We are now ready to configure In sequence to handle requests from the client.From the Mediators palette, click and drag a Log mediator to the In sequence (the top of the canvas).
With the Log mediator selected, access the Properties tab and fill in the information in the table below:
We will now add the property that will extract the stock symbol from the request and print a welcome message in the log. Click the Value field of the Properties property, and then click the browse (...) icon that appears.
In the Log Mediator Configuration dialog, click New, and then add a property called "message" as follows:
Name: message
Type: LITERAL
We select LITERAL because the required the log message is a static value.Value/Expression: "Welcome to HealthcareService"
Click OK to save the Log mediator configuration.We will now configure the Send Mediator to send the request message to the HealthcareService endpoint.
From the Mediators palette, click and drag a Send mediator to the In sequence adjoining the Log mediator you added above. Adjoining this, click and drag the QueryDoctorEP we created above the Defined EndPoints palette.
From the Mediators palette, click and drag a Send mediator to the Out Sequence (the bottom part of the canvas).