Unexpected "PROPAGATION_REQUIRES_NEW" camel transaction behavior with split()
Issue
camel route
from("timer://foo?repeatCount=1").routeId("route1")
.log("now in route1")
.setBody(simple("1\n"+"2"))
.to("direct:transactedRoute")
.log("back to route1");
from("direct:transactedRoute").routeId("route2")
.log("now in route2")
.transacted("PROPAGATION_REQUIRES_NEW")
.split(body().tokenize("\n"))
.log("inLoop route2")
.to("sql:insert into books (title) values ('Camel in Action2')")
.log("after camel-sql component")
.end();
beans.xml
<jdbc:embedded-database id="dataSource" type="DERBY">
<jdbc:script location="classpath:sql/init.sql"/>
</jdbc:embedded-database>
<bean
class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="txManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean class="org.apache.camel.spring.spi.SpringTransactionPolicy" id="PROPAGATION_REQUIRES_NEW">
<property name="transactionManager" ref="txManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>
</bean>
logback.xml
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
<logger name="org.springframework.jdbc.datasource.DataSourceTransactionManager" level="trace" />
1 commit is expected, but 4 commit are obserbed.
4:17:47.390 [main] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.23.2.fuse-7_10_2-00001-redhat-00005 (CamelContext: MyCamel) started in 0.154 seconds
14:17:47.401 [main] INFO org.mycompany.Application - Started Application in 4.176 seconds (JVM running for 4.486)
14:17:48.404 [Camel (MyCamel) thread #1 - timer://foo] INFO route1 - now in route1
14:17:48.409 [Camel (MyCamel) thread #1 - timer://foo] INFO route2 - now in route2
14:17:48.414 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Creating new transaction with name [null]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT
14:17:48.430 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Acquired Connection [org.apache.derby.impl.jdbc.EmbedConnection@1153436797 (XID = 173), (SESSIONID = 3), (DATABASE = memory:dataSource), (DRDAID = null) ] for JDBC transaction
14:17:48.432 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Switching JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@1153436797 (XID = 173), (SESSIONID = 3), (DATABASE = memory:dataSource), (DRDAID = null) ] to manual commit
14:17:48.432 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Suspending current transaction, creating new transaction with name [null]
14:17:48.434 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Acquired Connection [org.apache.derby.impl.jdbc.EmbedConnection@415652386 (XID = 175), (SESSIONID = 5), (DATABASE = memory:dataSource), (DRDAID = null) ] for JDBC transaction
14:17:48.434 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Switching JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@415652386 (XID = 175), (SESSIONID = 5), (DATABASE = memory:dataSource), (DRDAID = null) ] to manual commit
14:17:48.441 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Suspending current transaction, creating new transaction with name [null]
14:17:48.441 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Acquired Connection [org.apache.derby.impl.jdbc.EmbedConnection@777916045 (XID = 177), (SESSIONID = 7), (DATABASE = memory:dataSource), (DRDAID = null) ] for JDBC transaction
14:17:48.441 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Switching JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@777916045 (XID = 177), (SESSIONID = 7), (DATABASE = memory:dataSource), (DRDAID = null) ] to manual commit
14:17:48.441 [Camel (MyCamel) thread #1 - timer://foo] INFO route2 - inLoop
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] INFO route2 - after camel-sql component
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCommit synchronization
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCompletion synchronization
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [org.apache.derby.impl.jdbc.EmbedConnection@777916045 (XID = 177), (SESSIONID = 7), (DATABASE = memory:dataSource), (DRDAID = null) ]
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCommit synchronization
14:17:48.449 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCompletion synchronization
14:17:48.450 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@777916045 (XID = 177), (SESSIONID = 7), (DATABASE = memory:dataSource), (DRDAID = null) ] after transaction
14:17:48.450 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Resuming suspended transaction after completion of inner transaction
14:17:48.450 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Suspending current transaction, creating new transaction with name [null]
14:17:48.450 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Acquired Connection [org.apache.derby.impl.jdbc.EmbedConnection@1719520944 (XID = 181), (SESSIONID = 9), (DATABASE = memory:dataSource), (DRDAID = null) ] for JDBC transaction
14:17:48.450 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Switching JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@1719520944 (XID = 181), (SESSIONID = 9), (DATABASE = memory:dataSource), (DRDAID = null) ] to manual commit
14:17:48.450 [Camel (MyCamel) thread #1 - timer://foo] INFO route2 - inLoop
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] INFO route2 - after camel-sql component
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCommit synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCompletion synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [org.apache.derby.impl.jdbc.EmbedConnection@1719520944 (XID = 181), (SESSIONID = 9), (DATABASE = memory:dataSource), (DRDAID = null) ]
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCommit synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCompletion synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@1719520944 (XID = 181), (SESSIONID = 9), (DATABASE = memory:dataSource), (DRDAID = null) ] after transaction
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Resuming suspended transaction after completion of inner transaction
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCommit synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCompletion synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [org.apache.derby.impl.jdbc.EmbedConnection@415652386 (XID = 175), (SESSIONID = 5), (DATABASE = memory:dataSource), (DRDAID = null) ]
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCommit synchronization
14:17:48.451 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCompletion synchronization
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@415652386 (XID = 175), (SESSIONID = 5), (DATABASE = memory:dataSource), (DRDAID = null) ] after transaction
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Resuming suspended transaction after completion of inner transaction
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCommit synchronization
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering beforeCompletion synchronization
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [org.apache.derby.impl.jdbc.EmbedConnection@1153436797 (XID = 173), (SESSIONID = 3), (DATABASE = memory:dataSource), (DRDAID = null) ]
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCommit synchronization
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] TRACE o.s.j.d.DataSourceTransactionManager - Triggering afterCompletion synchronization
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [org.apache.derby.impl.jdbc.EmbedConnection@1153436797 (XID = 173), (SESSIONID = 3), (DATABASE = memory:dataSource), (DRDAID = null) ] after transaction
14:17:48.452 [Camel (MyCamel) thread #1 - timer://foo] INFO route1 - back to route1
Environment
- Red Hat Fuse
- 7.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.