如何让Mule将JDBC查询中的多行作为单个事务返回?

时间:2012-12-04 21:08:34

标签: mule

如果我在Oracle表中有100行,我希望收到一封包含100行的电子邮件,而不是100封电子邮件,每行一封...我认为transactionPerMessage会这样做(工具提示说,“如果为false,整个结果集将会有一个事务”,但无论我将其设置为true还是false,都没有区别。

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:jbossts="http://www.mulesoft.org/schema/mule/jbossts" xmlns:jdbc="http://www.mulesoft.org/schema/mule/jdbc" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.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/jbossts http://www.mulesoft.org/schema/mule/jbossts/current/mule-jbossts.xsd ">
    <jdbc:oracle-data-source name="Oracle_Data_Source" user="test" password="test" url="jdbc:oracle:thin:@//ora:1530/TEST.EXAMPLE.COM" transactionIsolation="UNSPECIFIED" doc:name="Oracle Data Source"/>
    <jdbc:connector name="Database" dataSource-ref="Oracle_Data_Source" validateConnections="true" transactionPerMessage="false" queryTimeout="-1" pollingFrequency="5000" doc:name="Database"/>
    <flow name="Ross_invoice_Workflow2Flow1" doc:name="Ross_invoice_Workflow2Flow1">
        <jdbc:inbound-endpoint queryKey="GetUnprocessedInvoices" queryTimeout="-1" pollingFrequency="1000" connector-ref="Database" doc:name="Database">
            <jdbc:query key="GetUnprocessedInvoices" value="SELECT        INVOICE_NUMBER FROM            FIN.LHF_INVOICE_WORKFLOW&#13;&#10;WHERE        (STATUS_FLAG = 'N')"/>
        </jdbc:inbound-endpoint>
        <echo-component doc:name="Echo"/>
        <smtp:outbound-endpoint host="mail.example.com" to="test@example.com" from="mule@example.com" subject="invoice test" responseTimeout="10000" doc:name="SMTP"/>
    </flow>
</mule>

2 个答案:

答案 0 :(得分:1)

让Mule按目前的方式每行创建一条消息,然后使用聚合器将消息分组100.您还必须在聚合器上配置最后一组可能不会达到100的超时(除非您的记录数始终是100的倍数。

答案 1 :(得分:0)

如果您还在端点上将transactionPerMessage属性设置为“true”并添加如下所示的事务,则连接器上的transactionPerMessage设置为“false”应该有效:

<jdbc:inbound-endpoint queryKey="GetUnprocessedInvoices" queryTimeout="-1"   pollingFrequency="1000" connector-ref="Database" doc:name="Database">
    <jdbc:query key="GetUnprocessedInvoices" value="SELECT        INVOICE_NUMBER FROM            FIN.LHF_INVOICE_WORKFLOW&#13;&#10;WHERE        (STATUS_FLAG = 'N')"/>
    <jdbc:transaction action="ALWAYS_BEGIN"/>
    <property key="receiveMessageInTransaction" value="true"/>
</jdbc:inbound-endpoint>