简体   繁体   中英

Understanding how Mule ESB fits in with JDBC and REST

I have this simple REST service running in our JBoss app server which works great. For now, the service has one @GET method (getAllPeople), which makes a JDBC connection to a mysql database, to retrieve some data (SELECT name, address FROM Person).

My team lead wants me to experiment with Mule ESB, and use this simple project as a starting point. I'm confused on how to make this work with a Mule flow. I set up my flow with an HTTP inbound point, REST component, and JDBC component, like this:

在此输入图像描述

I configured the JDBC component to use MySQL, and added a query to it (SELECT name, address FROM Person).

The question: The code in my REST service @GET method is still connecting directly to the DB with JDBC. I think I need to change this to instead, invoke the Mule JDBC datasource instead, but I have no idea how to do this. What code do I need to put in my REST service @GET method to utilize the Mule JDBC component, and get a result? I am trying to get a grasp on how the components talk to each other.

EDIT: new thought - Should an ESB be used to link different components of a single system together, such as REST services, SOAP services, and JDBC data sources, or should an ESB be used only to connect completely independent systems together?

To make your trivial example work, just delete the REST component and add an Object to JSON transformer after the JDBC component. Your flow will then return the query results in JSON format.

We can use mule here to call the rest api, rest api will return some data that may not be sufficient. In order to get more data from db based on the result of rest call (transformed by JsontoObject) jdbc connector could be used. In your case if you want to call rest api which eventually calls the DB, you will get json or xml which can be transformed to send the data to outbounds.

Thanks-

I am not sure why you have that 'rest' component in between. that may not be needed. the simplest would be to have the http, and a transformer (to transform the data from http to/from), and a jdbc component. with this approach you are leaving behind the existing ReST service in JBoss App Server.

I think in the posted picture you try to call the pre-existing ReST service in Jboss App Server which may not be needed. You can simply immitate what the existing service does. or you may consider the existing service and the new mule service can act as a proxy service - in such a case the JDBC component is not required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM