Skip to content

Exposing a Carbon Datasource as a Data Service

A Carbon datasource is an RDBMS or a custom datasource created using the Micro Integrator. You can simply use that as the datasource for a data service. A Carbon datasource is persistent, and can be used whenever required.

Synapse configurations

Given below is the data service configuration you need to build. See the instructions on how to build and run this example.

  • Carbon datasource

        <description>MySQL Connection</description>
        <jndiConfig useDataSourceFactory="false">
        <definition type="RDBMS">
  • Data service

    <data name="RDBMSDataService_3" transports="http https local">
       <config enableOData="false" id="Datasource">
          <property name="carbon_datasource_name">rdbms_datasource_mysql</property>
       <query id="GetEmployeeDetails" useConfig="Datasource">
          <sql>select EmployeeNumber, FirstName, LastName, Email, Salary from Employees where EmployeeNumber=:EmployeeNumber</sql>
          <result element="Entries" rowName="Entry">
             <element column="EmployeeNumber" name="EmployeeNumber" xsdType="string"/>
             <element column="FirstName" name="FirstName" xsdType="string"/>
             <element column="LastName" name="LastName" xsdType="string"/>
             <element column="Email" name="Email" xsdType="string"/>
             <element column="Salary" name="Salary" xsdType="string"/>
          <param name="EmployeeNumber" sqlType="STRING"/>
       <operation name="GetEmployeeOp">
          <call-query href="GetEmployeeDetails">
             <with-param name="EmployeeNumber" query-param="EmployeeNumber"/>
       <resource method="GET" path="Employee/{EmployeeNumber}">
          <call-query href="GetEmployeeDetails">
             <with-param name="EmployeeNumber" query-param="EmployeeNumber"/>

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Download the JDBC driver for MySQL from here and copy it to the MI_HOME/lib directory.


    If you are running this sample using the embedded Micro Integrator of WSO2 Integration Studio, the lib directory is located in MI_TOOLING_HOME/Contents/Eclipse/runtime/microesb/ (for Linux/MacOS/CentOS) or MI_TOOLING_HOME/runtime/microesb/lib/ (for Windows).

    If the driver class does not exist in the relevant directory when you create the datasource, you will get an exception such as Cannot load JDBC driver class com.mysql.jdbc.Driver.

  3. Create a Datasource project and then create a datasource.

  4. Create a Data Service project and then create the data service with the configurations given above.
  5. Deploy the artifacts in your Micro Integrator.

The service can be invoked in REST-style via curl ( ). Shown below is the curl command to invoke the GET resource:

curl -X GET http://localhost:8290/services/RDBMSDataService_3.HTTPEndpoint/Employee/3

This generates a response as follows.

<Entries xmlns=""><Entry><EmployeeNumber>3</EmployeeNumber><FirstName>Will</FirstName><LastName>Smith</LastName><Email></Email><Salary>15500.0</Salary></Entry><Entry><EmployeeNumber>3</EmployeeNumber><FirstName>Will</FirstName><LastName>Smith</LastName><Email></Email><Salary>15500.0</Salary></Entry><Entry><EmployeeNumber>3</EmployeeNumber><FirstName>Will</FirstName><LastName>Smith</LastName><Email></Email><Salary>15500.0</Salary></Entry></Entries>