You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Neeraj Mahajan <ne...@specsavers.com> on 2013/02/22 10:59:41 UTC

Issue with using multiple transaction managers of different types on two different routes in same camel-context.xml

I have one camel route which is listening on an Activmq consumer endpoint and
calls another direct route which do some persistence work.

In the first route i have injected transaction policy which is using JMS
transaction manager and in the second route I have intected other
transaction policy which is using Hibernate transaction manager.

The issue I am facing is my transaction policy for Hibernate transaction
manager is not working when I am using transaction policy for JMS
transaction manager in the first route.

If i remove the JMS transaction policy in the first route, my Hibernate
transaction policy works in the second route.

This problem I am facing in camel 2.6 , but in camel 1.6 everything is
working perfectly.

Please suggest.



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-using-multiple-transaction-managers-of-different-types-on-two-different-routes-in-same-cal-tp5728012.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with using multiple transaction managers of different types on two different routes in same camel-context.xml

Posted by Neeraj Mahajan <ne...@specsavers.com>.
Thanks Claus for your reply, I am not sure whether using the transaction
manager(XA) that can bind multiple resources in one transaction would
resolve my problem or not, because I dont need database operation to be part
of JMS transaction as I am sending a response(sucess/failure) after my
database operation. Also i need my response posting to be part of database
operation transaction. ie if my response posting get failed my database
state should be rollback.

My requirement is like this.

1 Consume message from an ActiveMq source queue

2 Persist the message in multiple tables in a database

3 Send  response on successResponse queue if there is no exception while
data persistense, otherwise send response on failureResponseQueue

4 If ther is any runtime exception occurs or response posting get failed
then the message should be reprocessed through redelivery, and if it remain
failed after all the redelivery attempts, then the message should be
transferred to the Dead Letter Queue.

Following is the snippet of my configuration

<camelContext id="myCamelContext"
xmlns="http://camel.apache.org/schema/spring">
		<route id="activeMqListenerRoute" errorHandlerRef="noErrorHandler">
			<from uri="activemq:sourceQueue" />
			<policy ref="jmsTransactionPolicy" />
			    <to uri="direct:persistenseRoute" />
		        </policy>
		</route>
		<route id="persistenseRoute" errorHandlerRef="noErrorHandler">
			<from uri="direct:persistenseRoute" />
			<doTry>
				<policy ref="databaseTransactionPolicy">
					<process ref="dataPersistenceProcessor" /> 
					<to uri="activemq:successResponseQueue" />
				</policy>
				<doCatch>
					<exception>com.my.organization.PersistenseException</exception>
                                        <process ref="exceptionLogger" />
					<to uri="activemq:failureResponseQueue" />
				</doCatch>
			</doTry>
		</route>
	</camelContext>

         <bean id="redeliveryPolicy"
class="org.apache.activemq.RedeliveryPolicy">
		<property name="maximumRedeliveries" value="5" />
	</bean>
	<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
		<property name="brokerURL"
			value="tcp://myBroker:61615?jms.watchTopicAdvisories=false" />
		<property name="redeliveryPolicy" ref="redeliveryPolicy" />
	</bean>
	<bean id="pooledJmsConnectionFactory"
class="org.apache.activemq.pool.PooledConnectionFactory">
		<property name="connectionFactory" ref="jmsConnectionFactory" />
	</bean>
	<bean id="jmsTransactionManager"
		class="org.springframework.jms.connection.JmsTransactionManager">
		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
	</bean>
	<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
		<property name="connectionFactory" ref="pooledJmsConnectionFactory" />
		<property name="transacted" value="true" />
		<property name="transactionManager" ref="jmsTransactionManager" />
	</bean>

	<bean id="jmsTransactionPolicy"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
		<property name="transactionManager" ref="jmsTransactionManager" />
		<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" />
	</bean>
	
	<bean id="databaseTransactionPolicy"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
		<property name="transactionManager" ref="transactionManager" />
		<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" />
	</bean>

	<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
		<property name="sessionFactory" ref="hibernateSessionFactory" />
	</bean>

       <bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"	>
		<property name="namingStrategy" ref="namingStrategy" />
		<property name="dataSource" ref="dataSource"/>
		<property name="configLocations">
		   
<value>com/myOrganization/mappings/hibernate/hibernate-mappings.xml</value>
		  </property>
		<property name="hibernateProperties"><ref
bean="hibernateProperties"/></property>	
	</bean>
	

        <bean id="dataSource" 
		class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="url"
value="jdbc:mysql://aristotle/aristotle?useUnicode=true&amp;characterEncoding=utf8"/>
		<property name="username" value="username"/>
		<property name="password" value="password"/>
		<property name="maxActive" value="5" />
		<property name="maxIdle" value="1" />
		<property name="initialSize" value="3" />
		<property name="poolPreparedStatements" value="true" />
		
		<property name="maxOpenPreparedStatements" value="10"/>
	</bean>	
	
	<bean id="namingStrategy"
class="org.hibernate.cfg.ImprovedNamingStrategy"/>
	
	<bean id="hibernateProperties"
class="com.myOrganization.dataservice.conf.HibernateProperties">
		<property name="databaseStartupAction" value="update"/>
		<property name="dialect"
value="org.hibernate.dialect.MySQLInnoDBDialect"/>
		<property name="showSql" value="false"/>
		<property name="useSecondLevelCache" value="true"/>
		<property name="cacheProvider"
value="org.hibernate.cache.EhCacheProvider"/>
		<property name="jdbcBatchSize" value="50" />
	</bean>
		
	Please suggest whether i am going into right direction or needs to change
my approach.
	



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-using-multiple-transaction-managers-of-different-types-on-two-different-routes-in-same-cal-tp5728012p5728078.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with using multiple transaction managers of different types on two different routes in same camel-context.xml

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You would need to use a transaction manager that supports both JMS and
JDCB - eg being XA capable. (2 phase commit).

Then configure your routes to use the same TX manager.


On Fri, Feb 22, 2013 at 10:59 AM, Neeraj Mahajan
<ne...@specsavers.com> wrote:
> I have one camel route which is listening on an Activmq consumer endpoint and
> calls another direct route which do some persistence work.
>
> In the first route i have injected transaction policy which is using JMS
> transaction manager and in the second route I have intected other
> transaction policy which is using Hibernate transaction manager.
>
> The issue I am facing is my transaction policy for Hibernate transaction
> manager is not working when I am using transaction policy for JMS
> transaction manager in the first route.
>
> If i remove the JMS transaction policy in the first route, my Hibernate
> transaction policy works in the second route.
>
> This problem I am facing in camel 2.6 , but in camel 1.6 everything is
> working perfectly.
>
> Please suggest.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Issue-with-using-multiple-transaction-managers-of-different-types-on-two-different-routes-in-same-cal-tp5728012.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen