Sunday, July 5, 2015

Use DBLookup Mediator in WSO2 ESB

DBLookup mediator is used to execute a sql query in to the synapse, it provides you result of sql query in property tag and which these properties can be used anywhere in service as required.
Above logic can be implemented in DSS also and it is very easy to do that but it depends on the requirement. Here we will only discuss dblookup in synapse level.
DBLookup mediator can be implemented in synapse directly or there is console UI configuration as well as mentioned below.

In the dblookup mediator you need to pass database name, url or whatever required to make a connection with the database and pass the sql query which needs to be run.

 This is the UI configuration of the DB lookup where you need to pass parameter to make a connection with the database.

This UI is for to make connection from the data source. To make connection you need to pass required values.

The entire above configuration can be implemented directly in the synapse file.

Synapse Code:

<dblookup xmlns="">
<property name="autocommit" value="false"/>
<statement><sql>select * from EMP_DETAILS where emp_id = ?</sql> <parameter expression="synapse:get-property(empID)" type="VARCHAR"/>
<result name="RequestNumber" column="REQUEST_NUMBER_V"/></statement>

In the above example employee id is the input parameter which you need to pass in parameter tag and you can get the detail whatever employee details has as required. Result of the query comes in result tag and there is a attribute in result tag which stored result data of query for a particular column which is attached with another attribute called column.