Mule 3.3.0 Jdbc Transaction Undesired Commit

2019-07-04 05:12发布

问题:

I'm trying to setup a dummy example of jdbc transaction to test commit and rollback. Here I've got :

  • an http entrypoint to start flow,
  • an insert on db a component that throw and exception
  • an update on db.

I expect that after component exception insert were rollback but it doesn't. Debugging mule source I've seen that in class BeginAndResolveTransactionInterceptor the insert statement terminate with a commit because resolveStartedTransaction property is set to true. This is why in default-exception-strategy rollback doesn't work I suppose... I don't know if I'm doing something wrong in configuration or if is a wrong behavior.

<spring:beans>
        <spring:bean id="sqlServerDataSource" name="sqlServerDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <spring:property name="password" value="${db.connection.password}"/>
            <spring:property name="url" value="${db.connection.url}"/>
            <spring:property name="username" value="${db.connection.username}"/>
            <spring:property name="driverClassName" value="${db.connection.driver_class}"/>
        </spring:bean>
        <spring:bean id="sqlServerSqlStatementStrategyFactory" name="sqlServerSqlStatementStrategyFactory" class="it.clesius.ebs.common.db.SqlServerSqlStatementStrategyFactory"/>
        <spring:bean id="DBRecord1" class="org.apache.commons.dbutils.handlers.BeanListHandler">
            <spring:constructor-arg value="it.clesius.esb.db.beans.DBRecord1"/>
        </spring:bean>
    </spring:beans>
<jdbc:connector name="JDBC_Connector" dataSource-ref="sqlServerDataSource" resultSetHandler-ref="DBRecord1" validateConnections="true" transactionPerMessage="false" queryTimeout="-1" pollingFrequency="0" doc:name="JDBC_Connector">
        <!-- jdbc:sqlStatementStrategyFactory ref="sqlServerSqlStatementStrategyFactory"/>
        <spring:property name="retryPolicyTemplate">
            <spring:bean class="org.mule.retry.policies.SimpleRetryPolicyTemplate">
                <spring:property name="count" value="10"/>
                <spring:property name="frequency" value="60000"/>
            </spring:bean>
        </spring:property -->

    </jdbc:connector>
    <flow name="DBTestFlow" doc:name="DBTestFlow">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="db" doc:name="HTTP"/>
        <message-properties-transformer doc:name="Add db properties">
            <add-message-property key="db.connection.driver_class" value="${db.connection.driver_class}"/>
            <add-message-property key="db.connection.password" value="${db.connection.password}"/>
            <add-message-property key="db.connection.url" value="${db.connection.url}"/>
            <add-message-property key="db.connection.username" value="${db.connection.username}"/>
        </message-properties-transformer>
        <jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="InsertTest" responseTimeout="10000" mimeType="text/plain" queryTimeout="-1" connector-ref="JDBC_Connector" doc:name="Database (JDBC)">
            <jdbc:transaction action="ALWAYS_BEGIN" />
            <!-- property key="receiveMessageInTransaction" value="true" /-->
            <jdbc:query key="InsertTest" value="INSERT INTO [ClesiusICEF_DEV].[dbo].[AAATEST_CANCELLLAMIPUREQUANDOVUOI] ([F1],[F2],[F3]) VALUES ('1','2','3')"/>
        </jdbc:outbound-endpoint>
        <component class="it.clesius.esb.ExceptionTest" doc:name="Break Flow with an Exception to Test Transaction Rollback"/>
        <jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="UpdateTest" responseTimeout="10000" mimeType="text/plain" queryTimeout="-1" connector-ref="JDBC_Connector" doc:name="Database (JDBC)">
            <jdbc:transaction action="ALWAYS_JOIN" />
            <jdbc:query key="UpdateTest" value="UPDATE [ClesiusICEF_DEV].[dbo].[AAATEST_CANCELLLAMIPUREQUANDOVUOI] SET [F1]='Aggiornato'"/>
        </jdbc:outbound-endpoint>
        <default-exception-strategy>
            <rollback-transaction exception-pattern="*"/>
            <logger level="INFO" message="!!!!!!!!!!TRANSAZIONE ANNULLATA!!!!!!!!!!!!!!!!!!!!!!!!!!!111" doc:name="Logger"/>
        </default-exception-strategy>
    </flow>

回答1:

ok I've found a workaround. If transaction is started by vm instead of jdbc it works fine. Probably there is a bug in jdbc/transaction that make commit always when first transactional endpoint is jdbc.