简体   繁体   English

了解Mule ESB如何适应JDBC和REST

[英]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. 我在我们的JBoss app服务器上运行这个简单的REST服务,效果很好。 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). 目前,该服务有一个@GET方法(getAllPeople),它与mysql数据库建立JDBC连接,以检索一些数据(SELECT名称,地址FROM Person)。

My team lead wants me to experiment with Mule ESB, and use this simple project as a starting point. 我的团队负责人希望我尝试使用Mule ESB,并以此简单项目为出发点。 I'm confused on how to make this work with a Mule flow. 我对如何使用Mule流程进行此操作感到困惑。 I set up my flow with an HTTP inbound point, REST component, and JDBC component, like this: 我使用HTTP入站点,REST组件和JDBC组件设置我的流程,如下所示:

在此输入图像描述

I configured the JDBC component to use MySQL, and added a query to it (SELECT name, address FROM Person). 我将JDBC组件配置为使用MySQL,并向其添加了一个查询(SELECT名称,地址FROM Person)。

The question: The code in my REST service @GET method is still connecting directly to the DB with JDBC. 问题:我的REST服务@GET方法中的代码仍然使用JDBC直接连接到DB。 I think I need to change this to instead, invoke the Mule JDBC datasource instead, but I have no idea how to do this. 我想我需要更改它,而是调用Mule JDBC数据源,但我不知道如何做到这一点。 What code do I need to put in my REST service @GET method to utilize the Mule JDBC component, and get a result? 我需要在REST服务@GET方法中使用什么代码来使用Mule JDBC组件,并获得结果? 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? 编辑:新想法 - 是否应该使用ESB将单个系统的不同组件链接在一起,例如REST服务,SOAP服务和JDBC数据源,或者ESB是否应仅用于将完全独立的系统连接在一起?

To make your trivial example work, just delete the REST component and add an Object to JSON transformer after the JDBC component. 要使您的简单示例工作,只需删除REST组件并在JDBC组件之后添加一个Object to JSON转换器。 Your flow will then return the query results in JSON format. 然后,您的流将以JSON格式返回查询结果。

We can use mule here to call the rest api, rest api will return some data that may not be sufficient. 我们可以在这里用mule来调用其余的api,rest api会返回一些可能不够的数据。 In order to get more data from db based on the result of rest call (transformed by JsontoObject) jdbc connector could be used. 为了根据rest调用的结果(由JsontoObject转换)从db获取更多数据,可以使用jdbc连接器。 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. 在你的情况下,如果你想调用最终调用数据库的rest api,你将得到json或xml,可以将其转换为将数据发送到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. 最简单的是拥有http和变换器(将数据从http转换为/来自)和jdbc组件。 with this approach you are leaving behind the existing ReST service in JBoss App Server. 使用这种方法,您将在JBoss App Server中留下现有的ReST服务。

I think in the posted picture you try to call the pre-existing ReST service in Jboss App Server which may not be needed. 我想在发布的图片中,您尝试在Jboss App Server中调用预先存在的ReST服务,这可能不需要。 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. 或者您可以认为现有服务和新的mule服务可以充当代理服务 - 在这种情况下,不需要JDBC组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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