Mule JDBC组合结果集

时间:2013-06-05 14:27:21

标签: mule

我有一个JDBC连接器作为入站端点,在我的数据库中获取正确的结果集 我注意到每一行都作为新消息返回。
我的问题:如何将所有行合并为一条消息?聚合器是唯一的选择吗?
使用Mule版本3.3.1 CE

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:mongo="http://www.mulesoft.org/schema/mule/mongo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/jdbc http://www.mulesoft.org/schema/mule/jdbc/current/mule-jdbc.xsd 
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/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd "    version="CE-3.3.1">




<context:property-placeholder location="configuration.properties" />
<spring:beans>
    <spring:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <spring:property name="driverClassName" value="mydriver"/>
        <spring:property name="url" value="${jdbc.url}"/>
        <spring:property name="username" value="${jdbc.user}"/>
        <spring:property name="password" value="${jdbc.password}"/>
    </spring:bean>
</spring:beans>

<jdbc:connector name="AS400" dataSource-ref="dataSource"
    validateConnections="true" 
    queryTimeout="-1" 
    pollingFrequency="5000"
    transactionPerMessage="false"
    doc:name="Database">
    <jdbc:query key="selectNums" value="select someColumns from someTable"/>

</jdbc:connector>


<flow name="databaseFlow" doc:name="databaseFlow" processingStrategy="synchronous">


    <jdbc:inbound-endpoint 

        queryKey="selectNums" queryTimeout="-1" connector-ref="AS400"
        doc:name="select-record" pollingFrequency="45000">
    </jdbc:inbound-endpoint>


    <logger message="msg to send:  #[map-payload:col1]" level="INFO" doc:name="Logger" />
    <logger message="phone number: #[map-payload:col2]" level="INFO" doc:name="Logger" />


    <custom-transformer class="myTransformer" doc:name="Java"/>

</flow>

1 个答案:

答案 0 :(得分:2)

要接收包含所有行的单条消息,请执行以下操作:

  1. 使用<jdbc:transaction action="ALWAYS_BEGIN"/>在JDBC入站端点中启动事务,并在JDBC端点上设置transactionPerMessage="false"

  2. 在流程开始时轮询JDBC出站端点:

    <poll frequency="${polling.frequency}">
        <jdbc:outbound-endpoint queryKey="..."
            exchange-pattern="request-response" queryTimeout="30000" />
    </poll>
    
  3. 在这两种情况下,您都会收到List<Map<String, Object>>有效负载的单条消息。