Atomikos Forum |
|
I have some tests that seem to demonstrate that the below Blueprint xml configuration does not enabled JTA/XA (Microsoft SqlServer + Apache ActiveMq) as expected. I am expecting that if an Java Exception is thrown and bubbles up through the container that the transaction gets rolled-back.
Any ideas? <atomikos.version>3.7.0</atomikos.version> <activemq.version>5.5.1</activemq.version> <camel.version>2.8.3</camel.version> <microsoft.sql-jdbc.version>3.0.1301</microsoft.sql-jdbc.version> <slf4j.version>1.6.1</slf4j.version> <spring.version>3.0.6.RELEASE</spring.version> <spring.osgi.version>1.2.1</spring.osgi.version> =================================================================== bundle/src/main/resources/OSGI-INF/blueprint/resource-context.xml =================================================================== <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd"> <!-- Properties in file: apache-servicemix-4.4.0\etc\resources.cfg --> <cm:property-placeholder persistent-id="resources" update-strategy="reload"> <cm:default-properties> <cm:property name="dbServerName" value="localhost" /> <cm:property name="dbServerPort" value="1433" /> <cm:property name="dbName" value="theDatbaseName" /> <cm:property name="dbUser" value="theDatabaseUser" /> <cm:property name="dbPassword" value="theDatabasePassword" /> <cm:property name="dbMaxConnectionPoolSize" value="30" /> </cm:default-properties> </cm:property-placeholder> <!-- Camel Specific Beans --> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="transactionManager" ref="jtaTransactionManager"/> <property name="cacheLevelName" value="CACHE_NONE"/> <property name="transacted" value="true"/> </bean> <bean id="jms" class="org.apache.camel.component.jms.JmsComponent"> <property name="transactionManager" ref="jtaTransactionManager"/> <property name="cacheLevelName" value="CACHE_NONE"/> <property name="transacted" value="true"/> </bean> <bean id="sql" class="org.apache.camel.component.sql.SqlComponent"> <property name="dataSource" ref="dataSource"/> </bean> <bean id="jdbc" class="org.apache.camel.component.jdbc.JdbcComponent"> <property name="dataSource" ref="dataSource"/> </bean> <!-- ################################################################################################################### # # # External Resources (JMS Connections + Database Connections) # # ################################################################################################################### --> <!-- http://blog.bigrocksoftware.com/2010/04/30/atomikos-activemq-hibernate/ http://activemq.apache.org/jms-and-jdbc-operations-in-one-transaction.html http://servicemix.396122.n5.nabble.com/JMS-and-Database-interactions-under-the-same-transactional-context-td4762819.html http://fusesource.com/forums/thread.jspa?threadID=3322&tstart=0 --> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" > <property name="forceShutdown" value="false" /> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" > <property name="transactionTimeout" value="150" /> </bean> <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="atomikosTransactionManager" /> <property name="userTransaction" ref="atomikosUserTransaction" /> <property name="allowCustomIsolationLevels" value="true" /> </bean> <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy"> <property name="transactionManager" ref="jtaTransactionManager" /> <property name="transactionTemplate" ref="transactionTemplate" /> <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED" /> </bean> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="jtaTransactionManager" /> <property name="isolationLevelName" value="ISOLATION_REPEATABLE_READ"/> <!-- <property name="timeout" value="10"/> --> </bean> <!-- JMS Connection Configuration --> <bean id="jmsXaConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> <property name="redeliveryPolicy"> <bean class="org.apache.activemq.RedeliveryPolicy"> <property name="initialRedeliveryDelay" value="1000"/> <property name="backOffMultiplier" value="5"/> <property name="useExponentialBackOff" value="true"/> <property name="maximumRedeliveries" value="6"/> </bean> </property> </bean> <bean id="atomikosConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="amq1" /> <property name="xaConnectionFactory" ref="jmsXaConnectionFactory" /> <property name="localTransactionMode" value ="false" /> <property name="maxPoolSize" value="${dbMaxConnectionPoolSize}" /> </bean> <!-- Database Connection Configuration --> <bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"> <property name="uniqueResourceName" value="ds1" /> <property name="testQuery" value="select 1" /> <property name="xaDataSource" ref="sqlServerXADataSource" /> </bean> <bean id="sqlServerXADataSource" class="com.microsoft.sqlserver.jdbc.SQLServerXADataSource"> <property name="serverName" value="${dbServerName}" /> <property name="portNumber" value="${dbServerPort}" /> <property name="selectMethod" value="cursor" /> <property name="databaseName" value="${dbName}" /> <property name="user" value="${dbUser}" /> <property name="password" value="${dbPassword}" /> </bean> </blueprint> ===================================================================
Sorry for the late reply, though I took some time to create a code example, so that I could share my ideas more effectively.
In the end, I think I got an example that works in the context of a Java Service Bean making JMS and JDBC calls, and multiple Camel Routes making JMS and JDBC calls. Source location: https://bitbucket.org/mark1900/test-osgi The OSGi Blueprint configuration lives here: https://bitbucket.org/mark1900/test-osgi/src/d536e2161ee4/test-osgi-blueprint-xa-atomikos/src/main/resources/OSGI-INF/blueprint README location: test-osgi/test-osgi-blueprint-xa-atomikos/README.txt
I don't know the breath of your integration experience though an input on the following would easily be appreciated.
The current configuration or the relevant Atomikos beans is here: == ServiceMix OSGi Aries Blueprint Atomikos Beans == https://bitbucket.org/mark1900/test-osgi/src/ff21eaa32e22/test-osgi-blueprint-xa-atomikos/src/main/resources/OSGI-INF/blueprint/resource-context.xml == Atomikos + Camel Integration to achieve XA Transactions == My Camel configuration using these Atomikos beans is here: https://bitbucket.org/mark1900/test-osgi/src/ff21eaa32e22/test-osgi-blueprint-xa-atomikos/src/main/resources/OSGI-INF/blueprint/xa-test-camel-context.xml == Atomikos + Pojo Service Integration to achieve XA Transactions == My Service configuration using these Atomikos beans is here: https://bitbucket.org/mark1900/test-osgi/src/ff21eaa32e22/test-osgi-blueprint-xa-atomikos/src/main/resources/OSGI-INF/blueprint/xa-test-service-context.xml As I am deploying to the ServiceMix 4.4.x environment and as such I had to use do my manual transaction management, which is given here: https://bitbucket.org/mark1900/test-osgi/src/ff21eaa32e22/test-osgi-blueprint-xa-atomikos/src/main/java/xo/transaction/XoTransactionProxyHandler.java
Hi,
just to understand a bit more about your problem and investigate the use of Atomikos OSGi into service mix I cloned your repo :https://bitbucket.org/pascalleclercq/test-osgi and made some little changes : 1. I replace SQLServer by Derby coz Derby is available as a OSGi bundle. 2. I use Atomikos OSGi bundle in version 3.8.0-SNAPSHOT which is our working bundle for making JTA OSGi. I faced some issues concerning about the namespace handler and decide to replece namespace part of XML conf I found here : https://github.com/cmoulliard/Devoxx-2011-HandsOnLab So far so good I don't have any stackTrace anymore in the log but I still have "XaTestExecutor.run(): FAILURE" in the console. Best regards |