Sending a Simple Message to a Service
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

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  back-end service. We configure an API resource in the ESB profile of WSO2 EI that receives the client request, ensuring that the client does not have to send messages directly to the back-end service, and thereby decoupling the client and the back-end service. 

 

In this tutorial, you will create a REST API in the ESB profile to connect to a REST back-end service that is defined as an HTTP endpoint in the ESB. If you want to see how information stored in a database can be used, see the tutorial on sending a simple message to a datasource.

 

Before you begin,

  • Download the product installer from here, and run the installer.

  • Select the relevant WSO2 Integration Studio based on your operating system and download it from here.
    The path to this folder is referred to as <EI_TOOLING> throughout this tutorial.

Let's get started!

This tutorial includes the following sections:

Creating the message mediation artifacts

Requests going through the ESB profile of WSO2 EI are called messages, and message mediation is a fundamental part of any ESB. In this section, we configure the message mediation process in the ESB profile that routes all received messages to the back-end service (healthcare service). We use the Eclipse-based WSO2 Integration Studio to create the message mediation artifacts and then deploy them to the ESB profile of WSO2 EI.

See the following topics for a description of the concepts that you need to know when creating ESB artifacts:

Creating the deployable artifacts project

Follow the steps given below to create an ESB solution project.

  1. Open WSO2 Integration Studio.

  2. Go to ESB Project and click Create New

  3. Enter SampleServices as the project name. Be sure to 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

  4. Click Finish.
    You have now created the following projects as shown in the Project Explorer:

Next, we create an endpoint inside the SampleServices ESB Solution project that will allow the ESB 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.

  1. Right-click SampleServices in the Project Explorer and navigate to New -> Endpoint.

  2. Ensure Create a New Endpoint is selected and click Next

  3. Enter the information given below to create the new endpoint.

  4. Click Finish
    The QueryDoctorEP endpoint is saved in the endpoints folder within the ESB Solution Project you created.

Now that you have created the endpoint for the back-end service, it is 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

Let's create a REST API named HealthcareAPI. Next, we 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.

  1. In the Project Explorer, right-click SampleServices and navigate to New -> REST API.

  2. Ensure Create A New API Artifact is selected and click Next.

  3. Enter the details given below to create a new REST API. 

  4. Click Finish
    Once the API resource is created, the design view of the HealthcareAPI.xml file will appear as shown below. You can now start configuring the API resource. 

  5. Double-click the Resource icon on the left side of the canvas. 
    The properties for the API resource appear on the Properties tab at the bottom of the window. If they do not appear, you can right-click the Resource icon and click Show Properties View.

  6. On the Properties tab, provide the following as Basic properties:


    We are now ready to configure the In sequence to handle requests from the client. 

  7. Configure the In sequence:

    1. From the Mediators palette, click and drag a Log mediator to the In sequence (the top of the canvas).

    2. With the Log mediator selected, access the Property tab and fill in the information in the table below:

    3. Click OK to save the Log mediator configuration.

    4. Configure the Send Mediator  to send the request message to the HealthcareService endpoint.

      1. From the Mediators palette, click and drag a Send mediator to the In sequence adjoining the Log mediator you added above. 

      2. From the Defined EndPoints palette, click and drag the QueryDoctorEP endpoint, which we created, right next to the empty space of the Send mediator.

  8. Configure the Out sequence to ensure that we send the response from the Healthcare service endpoint back to the client. For this, we use a Send mediator with no output endpoint defined, which defaults to sending the response back to the requesting client.
    From the Mediators palette, click and drag a Send mediator to the Out Sequence (the bottom part of the canvas).

You have successfully created all the artifacts that are required to send a request through the ESB to the back-end service. We will now package these artifacts and deploy them in the ESB profile of WSO2 EI.

Packaging the artifacts

You need to Package the QueryDoctorEP endpoint and the HealthcareAPI resource into the Composite Application (C-App) project named SampleServicesCompositeApplication, which we already created.

  1. Open the pom.xml file of the C-App project in the Composite Application Project POM Editor. 

  2. Select the artifact that needs to be included into the CAR file as shown above.

  3. Save the POM file.

Starting the ESB profile and deploying the artifacts

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.