Narayana事务管理器集成Camel+Spring时事务不回滚问题
Narayana事务管理器与Camel、Spring集成事务回滚异常问题
我正在配置Narayana Transaction Manager与Camel、Spring的集成环境,已创建两个数据源对象,分别用于向两个不同数据库插入记录。在第一条记录插入后主动抛出异常,预期事务会触发回滚,但日志显示事务管理器已启动,却未执行回滚操作。
camel-context.xml配置
<?xml version="1.0" encoding="UTF-8"?> <!-- Configures the Camel Context--> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <bean id="dataSource1" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.arjuna.ats.jdbc.TransactionalDriver" /> <property name="url" value="jdbc:mysql://localhost:3306/jdbctest" /> <property name="username" value="root" /> <property name="password" value="Govinda@1" /> </bean> <bean id="dataSource2" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.arjuna.ats.jdbc.TransactionalDriver" /> <property name="url" value="jdbc:mysql://localhost:3306/springtransaction1" /> <property name="username" value="root" /> <property name="password" value="Govinda@1" /> </bean> <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <bean class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple" /> </property> <property name="userTransaction"> <bean class="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple" /> </property> </bean> <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy"> <property name="transactionManager" ref="jtaTransactionManager" /> <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" /> </bean> <bean id="myError" class="com.rwx.camelspringnarayana.MyError" /> <camelContext xmlns="http://camel.apache.org/schema/spring"> <!-- here is a sample which processes the input files (leaving them in place - see the 'noop' flag) then performs content based routing on the message using XPath --> <route> <from uri="timer:myTimer1?repeatCount=1" /> <transacted ref="PROPAGATION_REQUIRED"/> <log message="timer1 started" /> <to uri="sql:insert into cars values(1896, 'Jaldut')?dataSource=#dataSource1" /> <bean ref="myError" /> <to uri="sql:insert into cars values(1922, 'Rwx Car')?dataSource=#dataSource1" /> <log message="${body}" /> </route> <route> <from uri="timer:myTimer2?repeatCount=1" /> <delay> <constant>5000</constant> </delay> <log message="timer2 started" /> <to uri="sql:select * from cars where car_no in (1896,1922)?dataSource=#dataSource1" /> <log message="${body}" /> </route> <route> <from uri="timer:myTimer4?repeatCount=1" /> <delay> <constant>5000</constant> </delay> <log message="timer 4 started" /> <to uri="sql:select * from user_tb where id =2 ?dataSource=#dataSource2" /> <log message="${body}" /> </route> <route> <from uri="timer:myTimer3?repeatCount=1" /> <delay><constant>10000</constant></delay> <log message="timer3 started" /> <to uri="sql:delete from cars where car_no in (1896,1922)?dataSource=#dataSource1" /> <log message="No of rows deleted are = ${headers.camelSqlUpdateCount}" /> </route> <route> <from uri="timer:myTimer5?repeatCount=1" /> <delay><constant>10000</constant></delay> <log message="timer 5started" /> <to uri="sql:delete from user_tb where id =2?dataSource=#dataSource2" /> <log message="No of rows deleted are = ${headers.camelSqlUpdateCount}" /> </route> </camelContext> </beans>
问题现象
即使抛出异常,事务仍未回滚,有一条记录被成功插入且可被删除,说明事务未执行回滚操作。
相关日志
[] [el (camel-1) thread #8 - Delay] route2 INFO [{car_no=1896, carName=Jaldut}] [l (camel-1) thread #10 - Delay] route5 INFO timer 5started [el (camel-1) thread #9 - Delay] route4 INFO timer3 started [l (camel-1) thread #10 - Delay] route5 INFO No of rows deleted are = 0 [el (camel-1) thread #9 - Delay] route4 INFO No of rows deleted are = 1
内容的提问来源于stack exchange,提问作者chandrahas g
相关产品推荐
相关产品推荐

