我正在尝试设置一个jdbc事务的虚拟示例来测试提交和回滚。我在这里:
我希望在组件异常插入之后进行回滚,但事实并非如此。 调试mule源我已经看到,在类BeginAndResolveTransactionInterceptor中,insert语句以commit结束,因为resolveStartedTransaction属性设置为true。 这就是为什么在默认 - 异常 - 策略回滚不起作用我想... 我不知道我在配置上做错了什么,或者是否是错误的行为。
<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>
答案 0 :(得分:0)
好的我找到了解决方法。如果事务是由vm而不是jdbc启动的,那么它可以正常工作。 可能在jdbc / transaction中有一个错误,它总是在第一次事务时进行提交 endpoint是jdbc。