camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neeraj Mahajan <neeraj.maha...@specsavers.com>
Subject Re: Issue with using multiple transaction managers of different types on two different routes in same camel-context.xml
Date Mon, 25 Feb 2013 06:05:20 GMT
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.

Mime
View raw message