Showing posts with label Atomikos. Show all posts
Showing posts with label Atomikos. Show all posts

Thursday, June 7, 2012

JTA Transaction Manager(XA) - Analysis


Requirements
We needs JTA complaint XA transaction manager since we have multiple resources
  • Database - Mysql
  • Cache - Infinispan
Both of these resources support XA - JTA transactions. - Mysql through com.mysql.jdbc.jdbc2.optional.MysqlXADataSource.
Alternatives for transaction manager 
We also need to choose a connection pool framework for database which is XA complaint. Hence options
Picking the right combination
  1. Atomokis transaction Manager + Atomikos connection pooling 
  • Easy configurations with Spring
  • JTA implementation comes with connection Pooling & Datasource (no need of seperate JCA)
  • Does support synchronization
  • Does not support last resource optimization
2. Jboss transaction Manager

      Jboss does not come with default connection pool  or JCA to be used in Standalone mode. Hence it is ideal with server liek Jboss and not in standalone mode
       Issues 
   1. Tried Jboss TM + DBCl Connection pool(XA) as suggested in  - http://lafernando.com/2011/01/05/xa-transactions-with-apache-dbcp/
   Faced issues were in connections got exhasted and where not returned to the pool
  2. Then tried to replace DBCP with Tomcat jdbc pool - which is the advanced version of dbcp overcoming its drawbacks
   Even though jdbc pool claims to have XA support , did not find much info about it in the net. When I tried the datasource did not seem to take part in the transaction.
 So the optiosn for JCA where 
Both these did not have any great documentation for use in standalone environment.
Based on all the above we will switch back to Atomikos  because
  1. It has Support
  2. Good documentation/ examples
  3. Seems to be widely used

Friday, May 11, 2012

Spring Configuratiosn for JTA Transaction - XA datasource (Mysql) + Atomikos Transaction manager + Spring Transaction annotations





Mysql complaint mysql xa datasource  and Atomikos connection pooling



 <bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
  init-method="init" destroy-method="close">
  <property name="uniqueResourceName" value="MAIN-ATOMIKOS-CONNECTION" />
  <property name="poolSize" value="${initialSize}" />
  <property name="xaDataSourceClassName"
   value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
  <property name="xaProperties" ref="databaseProperties" />
  <property name="testQuery" value="select 1" />
 </bean>




database.properties


<util:properties id="databaseProperties"
  location="classpath:database.properties" />



url=jdbc\:mysql\://localhost\:3306/<DBNAME>
user=root
password=
autoReconnect=true
autoReconnectForConnectionPools=true
autoReconnectForPools=true
pinGlobalTxToPhysicalConnection=true


Transaction specific Config

Following settings are for enabling transactions

<tx:annotation-driven transaction-manager="transactionManager" />

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" 
  init-method="init" destroy-method="close"> 
           <property name="forceShutdown"> <value>true</value> </property> 
</bean>

<bean id="atomikosUserTransaction" 
  class="com.atomikos.icatch.jta.UserTransactionImp">
            <property name="transactionTimeout" 
  value="300"/> 
</bean> 

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> 
  <property name="transactionManager"> <ref bean="atomikosTransactionManager" 
  /> </property> 
              <property name="userTransaction"> <ref bean="atomikosUserTransaction" 
  /> </property> 
</bean> 




Just adding spring Spring annotation - will now enable transaction on required methods.


 
Free Domain Names @ .co.nr!