我正在尝试设置一个 jdbc 事务的虚拟示例来测试提交和回滚。在这里我有:
- 启动流程的 http 入口点,
- 在 db 上插入一个抛出异常的组件
- db的更新。
我希望在组件异常插入后回滚,但事实并非如此。调试骡源我已经看到,在类 BeginAndResolveTransactionInterceptor 中,插入语句以提交终止,因为 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>