camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian <>
Subject Re: ActiveMQ stuck message using JTA Transactions
Date Tue, 15 Mar 2011 22:35:17 GMT
Thanks for your response. As mentioned I cleaned up the routes to be as 
basic as possible to replicate the issue we are facing. Let me describe 
why we have this type of routing and what we are trying to accomplish...

   1. Start transaction 1
   2. Consume message from queue foo
   3. Perform some business logic to modify the message (Not shown in
      sample routes)
   4. Send off to direct:bar to continue routing
   5. Suspend Transaction 1
   6. Start a new Transaction 2
   7. Perform some business logic to modify message (Not shown in sample
   8. Insert message into a database (Not shown in sample routes)
   9. Put message into queue bar
  10. Commit Transaction 2
  11. Resume Transaction 1
  12. Commit Transaction 1

The reason for the multiple transactions is that if an error occurs 
inside Transaction 2 we want to rollback whatever occurred in 
Transaction 2 and we still want Transaction 1 to resume and then 
eventually commit so the message is then finally removed from foo queue. 
My understanding is that transactions are based on a single thread and 
when using direct routing that will process the next route in the same 
thread allowing use to suspend and resume transactions.

We used the example "Using multiple routes with different propagation 
behaviors" describe on the Camel Website at as a basis for 
implementing this routing.

It appears this issue arises when integrating with ActiveMQ, Spring JTA 
TransactionManager and also Atomikos. I did see a reference to JMS 
sending blocks identified on the Atomikos documentation 
which describes a similar problem to what we are seeing happening. It 
appears to fix that blocking you must set the "sessionTransaction" 
attribute which we tried and it still does not work. I am posting on 
camel to see if there is any issues with how the behind the scenes 
consuming and producing from a queue is generated and how it integrates 
with JTA transactions.

Included again for reference since the XML does not display in the 
actual mailing list mails.

<camel:camelContext trace="true">
		<camel:from uri="activemq:queue:foo" />
		<camel:transacted ref="PROPAGATION_REQUIRED"/>
		<camel:to uri="direct:bar"/>
		<camel:from uri="direct:bar" />
		<camel:transacted ref="PROPAGATION_REQUIRES_NEW"/>
		<camel:inOnly uri="activemq:queue:bar"/>

<!-- define the activemq Camel component so we can integrate with the AMQ broker below
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
	<property name="transactionManager" ref="jtaTransactionManager"/>
	<property name="transacted" value="true"/>
	<property name="connectionFactory" ref="atomikosJmsConnectionFactory"/>

<!-- JTA Transaction Manager Setup -->
<!-- this is the Spring JtaTransactionManager which under the hood uses Atomikos -->
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
	<property name="transactionManager" ref="atomikosTransactionManager"/>
	<property name="userTransaction" ref="atomikosUserTransaction"/>

<!-- Is the ConnectionFactory to connect to the JMS broker -->
<!-- notice how we must use the XA connection factory -->
<bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
	<property name="brokerURL" value="tcp://localhost:61616"/>
<!-- Atomikos Setup -->
<!-- setup Atomikos for XA transaction -->
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
	<!-- when close is called, should we force transactions to terminate or not? -->
	<property name="forceShutdown" value="false"/>

<!-- this is some atomikos setup you must do -->
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
	<property name="transactionTimeout" value="300"/>

<!-- this is some atomikos setup you must do -->
<bean id="atomikosJmsConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean"
init-method="init" destroy-method="close">
	<property name="uniqueResourceName" value="amq1"/>
	<property name="xaConnectionFactory" ref="jmsXaConnectionFactory"/>

<!-- This is the default behavior. -->
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
	<property name="transactionManager" ref="jtaTransactionManager"/>

<bean id="PROPAGATION_REQUIRES_NEW" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
	<property name="transactionManager" ref="jtaTransactionManager"/>
	<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"/>

*Brian Osborne | xFact, Inc.*
120 Water Street, Suite 214
North Andover, MA 01845
p. 978.686.3180 | c. 508.314.4627 | f. 978.824.2308 |

On 3/15/2011 5:27 PM, Ashwin Karpe [via Camel] wrote:
> Hi,
> It is quite unclear why/what you are really trying to do.
> First, When you say PROPAGATION_REQUIRED, you pass the transaction 
> context along the route hoping that somewhere along the way following 
> proper processing, the exchange will come back in a state where a 
> commit/rollback can be done on this transaction.
> But halfway through, (Note you are using direct: an in-memory 
> component), you stomp the original transaction to create a new 
> transaction without sending back an success/fail on the original leg. 
> This is what is causing problems you are seeing, I believe.
> If you create 2 distinct routes, not using direct but rather (http, 
> mina/netty, jms) then you should be able to create 2 separate and 
> distinct routes where the traction boundary does not carry forward 
> beyond the transport producer. Then I believe it should work.
> Cheers,
> Ashwin...
> ---------------------------------------------------------
> Ashwin Karpe
> Apache Camel Committer & Sr Principal Consultant
> FUSESource (a Progress Software Corporation subsidiary)
> Blog:
> ---------------------------------------------------------
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:

> To unsubscribe from ActiveMQ stuck message using JTA Transactions, 
> click here 
> <>.


View this message in context:
Sent from the Camel - Users mailing list archive at
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message