This documentation is for WSO2 Enterprise Integrator version 6.2.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

All docs This doc
Skip to end of metadata
Go to start of metadata

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,

  1. Install Oracle Java SE Development Kit (JDK) version 1.8.* and set the JAVA_HOME environment variable.
  2. 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.
  3. 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> through out this tutorial.

    Getting an error message? See the troubleshooting tips given under Installing Enterprise Integrator Tooling.

  4. 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.
  5. Download the MSF4J service from here and copy the JAR file to <EI_HOME>/wso2/msf4j/deployment/microservices folder. 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 payment.

  1. Right click SampleServices in the Project Explorer and navigate to New -> Endpoint. Ensure Create a New Endpoint is selected and click Next.

  2. Fill in the information as in the following table:

    Field
    Value
    Endpoint NameChannelingFeeEP
    Endpoint TypeHTTP Endpoint
    URI Templatehttp://localhost:9090/{uri.var.hospital}/categories/appointments/{uri.var.appointment_id}/fee
    MethodGET
    Static Endpoint(Select this option because we are going to use this endpoint in this ESB Config project only and will not re-use it in other projects.)
    Save Endpoint inSampleServices

    Click Finish.

  3. Create another endpoint for Settle Payment and fill in the information as in the following table: 

    Field
    Value
    Endpoint NameSettlePaymentEP
    Endpoint TypeHTTP Endpoint
    URI Template

    http://localhost:9090/healthcare/payments

    MethodPOST
    Static Endpoint(Select this option because we are going to use this endpoint in this ESB Config project only and will not re-use it in other projects.)
    Save Endpoint inSampleServices

    Click Finish.

You have now created the additional endpoints that are required for this tutorial. 

Creating the deployable artifacts

  1. 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:

    Field
    Value
    Property NameSelect New Property
    New Property Namecard_number
    Property Action

    Select set

    Value TypeSelect Expression
    Value Expressionjson-eval($.cardNo)
    DescriptionGet Card Number

    For detailed instructions on adding a Property mediator, see Mediating requests to the back-end service.

  2. 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.hospital variable 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:

    Field
    Value
    Property NameSelect New Property
    New Property Nameuri.var.hospital
    Property Action

    Select set

    Value TypeSelect LITERAL
    Property Data TypeSelect STRING
    Valuegrandoaks
    DescriptionSet Hospital Variable
  3. Similarly, add property mediators in the other two case boxes in the Switch mediator. Change only the Value field as follows:
    • Case 2: clemency
    • Case 3: pinevalley
      set property mediator for all cases
  4. 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.
    add call mediators to all cases

    Replacing with a Call mediator allows us to define other service invocations following this mediator.

    Let's use Property mediators to retrieve and store the values that you get from the response you receive from GrandOakEP, ClemencyEP or PineValleyEP.

  5. Next to the Switch mediator, add a Property mediator to retrieve and store the value sent as appointmentNumber.

    add the Get Appointment Number property mediator

    With the Property mediator selected, access the Properties tab and fill in the information as in the following table:

    Field
    Value
    Property NameSelect New Property
    New Property Nameuri.var.appointment_id
    (This value is used when invoking ChannelingFeeEP)
    Property Action

    Select set

    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.appointmentNumber)
    DescriptionGet Appointment Number

    You derive the Value Expression in the above table from the following response that is received from GrandOakEP, ClemencyEP or PineValleyEP:

    {"appointmentNumber":1,   "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}
  6. Similarly, add two more Property mediators as follows. They retrieve and store the doctor details and patient details respectively, from the response that is received from GrandOakEP, ClemencyEP or PineValleyEP.

    Field
    Value
    Property NameSelect New Property
    New Property Namedoctor_details
    Property Action

    Select set

    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.doctor)
    DescriptionGet Doctor Details


    Property NameSelect New Property
    New Property Namepatient_details
    Property ActionSelect set
    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.patient)
    DescriptionGet Patient Details

    add the last two property mediators

  7. Add a Call mediator and add ChannelingFeeEP from Defined Endpoints palette to the empty box adjoining the Call mediator. 
  8. 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:

    Field
    Value
    Property NameSelect New Property
    New Property Nameactual_fee (This value is used when invoking SettlePaymentEP )
    Property Action

    Select set

    Value TypeSelect EXPRESSION
    Value Expressionjson-eval($.actualFee)
    DescriptionGet Actual Fee

    actual fee

    You derive the Value Expression in the above table from the following response that is received from ChannelingFeeEP:

    {"patientName":" John Doe ", 
     "doctorName":"thomas collins", 
     "actualFee":"7000.0"}

    Let'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"
    }
  9. Next to the Property mediator, add a PayloadFactory mediator from the mediators palette to construct the above message payload. 

    add the payload factory mediator

    With the Payloadfactory mediator selected, access the properties tab of the mediator and fill in the information as in the following table:

    Field
    Value
    Description
    Payload FormatSelect Inline-
    Media Type

    Select json

    -
    Payload

    {
    "appointmentNumber":$1,
    "doctor":$2,
    "patient":$3,
    "fee":$4,
    "confirmed":"false",
    "card_number":"$5"
    }

    The message payload to send with the request to SettlePaymentEP. In this payload, $1, $2, $3, $4 and $5 indicate variables.

    We will look at adding the value for the field Args in the following steps.

    To avoid getting an error message, first select the Media Type before providing the Payload.

  10. 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.

    Field
    Value
    Description
    TypeSelect Expression-
    Value

    $ctx:uri.var.appointment_id

    The value for the first variable ($1) in the message payload format.
    Evaluator

    Select xml

    Indicates that the expression provided is in XML.

    The $ctx method is similar to using the get-property method. This method checks in the message context. For more details on using this method, refer the documentation.

  11. 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_number

  12. Add a Call mediator and add SettlePaymentEP from Defined Endpoints palette to the empty box adjoining the Call mediator.
  13. Add a Respond mediator to send the response to the client. 

    You should now have a completed configuration that looks like this:
  14. Save the updated REST API configuration.

Packaging the artifacts

Since you created new endpoints, these will need to be packaged into our existing C-App. 

Package the C-App names SampleServicesCompositeApplication project with the artifacts created. 

Ensure the following artifact check boxes are selected in the Composite Application Project POM Editor.

  • SampleServices
    • HealthcareAPI
    • ClemencyEP
    • GrandOakEP
    • PineValleyEP
    • ChannelingFeeEP
    • SettlePaymentEP
  • SampleServicesRegistry

Starting the ESB runtime and deploying the artifacts

On the Servers tab, expand the WSO2 Carbon server, right-click SampleServicesCompositeApplication, and choose Redeploy. The Console window will indicate that the C-App has been deployed successfully.

If you do not have a server added in Eclipse, refer this tutorial.

You can also deploy the artifacts to the ESB profile of WSO2 EI using a Composite Application Archive (CAR) file

Starting the MSF4J profile

To be able to send requests to the back-end service (which is an MSF4J service deployed in the MSF4J profile), you need to first start the MSF4J runtime:

  1. Open a terminal and navigate to the <EI_HOME>/wso2/msf4j/bin directory.
  2. Start the runtime by executing the MSF4J startup script as shown below.

    sh carbon.sh

The Healthcare service is now active and you can start sending requests to the service.

Sending requests to the ESB

  1. Create a JSON file names request.json with the following request payload.

    {
    "name": "John Doe",
    "dob": "1940-03-19",
    "ssn": "234-23-525",
    "address": "California",
    "phone": "8770586755",
    "email": "johndoe@gmail.com",
    "doctor": "thomas collins",
    "hospital": "grand oak community hospital",
    "cardNo": "7844481124110331",
    "appointment_date": "2017-04-02"
    }
  2. Open a command line terminal and execute the following command from the location where request.json file you created is saved:

    curl -v -X POST --data @request.json http://localhost:8280/healthcare/categories/surgery/reserve --header "Content-Type:application/json"

    This is derived from the URI-Template defined when creating the API resource.

    http://<host>:<port>/categories/{category}/reserve

    You will see the response as follows:

    {"patient":"John Doe",
     "actualFee":7000.0,
     "discount":20,
     "discounted":5600.0,
     "paymentID":"e2781025-5332-4a78-950b-3be83c99fa76",
     "status":"Settled"}

You have now explored how the ESB profile of WSO2 EI can do service chaining using the Call mediator and transform message payloads from one format to another using the PayloadFactory mediator.

  • No labels