??????????????????? 在mule3.4.0中和jdbc的整合简单需求如下:向一个vm:queue发送map消息, mule根据map信息, 动态执行sql, insert 插入语句.
???????????? 在mule3.4中,官方推荐采用flow而不是model方式配置.官方警告信息如下:
[08-20 14:49:22] WARN? SedaModel [main]: The <model> element is deprecated in Mule 3.4 and will be removed in Mule 4.0.? Flows do not need to be configured inside a <model> element.
[08-20 14:49:22] WARN? SedaService [main]: Services (SedaService or any custom implementation) are deprecated in Mule 3.4 and will be removed in Mule 4.0.
?
mule-jdbc-config-service.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd"> <vm:connector name="vmQueue"/> <endpoint address="vm://query" name="query" exchange-pattern="one-way"/> <!-- 創建數據源 --> <spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <spring:property name="driverClassName" value="com.mysql.jdbc.Driver" /> <spring:property name="url" value="jdbc:mysql://localhost/dbtest2" /> <spring:property name="username" value="root" /> <spring:property name="password" value="root" /> <spring:property name="maxActive" value="30" /> <spring:property name="maxIdle" value="10" /> <spring:property name="maxWait" value="1000" /> <spring:property name="defaultAutoCommit" value="true" /> </spring:bean> <!-- 創建sql 語句 --> <jdbc:connector name="jdbcConnector" dataSource-ref="dataSource"> <jdbc:query key="selectUser" value="SELECT first_name,last_name FROM app_user where first_name=#[map-payload:firstName]" /> <jdbc:query key="insertUser" value="insert into app_user (id,first_name,last_name ) values(#[map-payload:id], #[map-payload:firstName], #[map-payload:lastName])" /> </jdbc:connector> <!-- The Mule model initialises and manages your UMO components --> <model name="databaseModel"> <service name="insertUMO"> <!-- any number of endpoints can be added to an inbound router --> <inbound> <vm:inbound-endpoint ref="query" /> </inbound> <!-- An outbound router can have one or more router configurations that can be invoked depending on business rules, message contents, headers or any other criteria. The pass-through-router is a router that automatically passes on every message it receives --> <outbound> <pass-through-router> <jdbc:outbound-endpoint queryKey="insertUser"/> </pass-through-router> </outbound> </service> </model> </mule