3
我想設置一個jdbc事務的虛擬示例來測試提交和回滾。在這裏,我已經有了:Mule 3.3.0 Jdbc事務不需要提交
- 一個http入口點開始流動,
- 插入數據庫上拋出一個組件和異常
- 分貝的更新。
我期望組件異常插入後回滾,但它不。 調試mule源我已經看到類BeginAndResolveTransactionInterceptor中的insert語句終止於提交,因爲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>
乍一看,你不會做任何錯誤的事情。在Mule 3.3.0中,引入了「回滾異常策略」:您應該嘗試一下。請參閱:http://www.mulesoft.org/documentation/display/MULE3USER/Rollback+Exception+Strategy,是的,我知道MuleSoft不會把XML放在他們的文檔中,但只是工作室的截圖:(但XML編輯器應該引導你在建立你的配置 –
你正在測試什麼db&jdbc驅動程序?我遇到了與使用jtds驅動程序的mssql服務器類似的問題,我用h2工作得很好,我打開了類似的問題:http://stackoverflow.com/questions/ 13650959/mule-esb-3-transactional-flow-single-jdbc-resource-not-rolling-back-mssql-jtd我的xml雖然不同(文檔很糟糕,所以誰知道哪個是對的):如果我在jdbc端點,它不起作用,我打開tx(無證) 緊跟在 之後 –
pakman