JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction")

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction")

MarkS1900

I have a Aries Blueprint file in my ServiceMix OSGi bundle, and I want to achieve JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction").

I am NOT using JPA, just raw JDBC calls.

How do I register my Xa Jms ConnectionFactory (org.apache.activemq.ActiveMQXAConnectionFactory) and my Xa DataSource (com.microsoft.sqlserver.jdbc.MySQLServerXADataSource) with the container's transaction manager?


<?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"
    >

   
    <reference id="ariesTransactionManager" interface="javax.transaction.TransactionManager" />

   
    <reference id="platformTransactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />
   
</blueprint>



I am expecting working code to take the following form:

--------  OPTION 1  --------


    <bean id="transactionServiceBean" class="test.xa.service.TransactionServiceBean">
        <property name="transactionManager" ref="platformTransactionManager" />
        <property name="persistenceHelper" ref="persistenceHelperXa" />
    </bean>

public class TransactionServiceBean
{
    //...
   
    public void doTransactionCommit()
    {

        LOG.info( "doTransactionCommit() ->" );

        TransactionStatus transactionStatus;

        try
        {
            transactionStatus = transactionManager.getTransaction( transactionDefinition );

        }
        catch( Exception e )
        {
            LOG.error( "Transaction failed:  ", e );
            return;
        }

        try
        {
            //  ...
            //  DO JMS AND JDBC STUFF HERE
            //  ...

            transactionManager.commit( transactionStatus );

        }
        catch( Exception e1 )
        {
            LOG.error( "Commit failed:  ", e1 );

            try
            {
                transactionManager.rollback( transactionStatus );
            }
            catch ( Exception e2 )
            {
                LOG.error( "Rollback failed:  ", e2 );
                throw new RuntimeException( e2 );
            }

            throw new RuntimeException( e1 );
        }

        LOG.info( "doTransactionCommit() <-" );


    }
   
    // ...
}

--------  OPTION 2  --------


    <bean id="transactionServiceBean" class="test.xa.service.TransactionServiceBean">
        <tx:transaction method="do*" value="RequiresNew" />
    </bean>

public class TransactionServiceBean
{
    //...
       
    public void doTransactionCommit()
    {

        LOG.info( "doTransactionCommit() ->" );

        //  ...
        //  DO JMS AND JDBC STUFF HERE
        //  ...

        LOG.info( "doTransactionCommit() <-" );


    }
   
    // ...
}





Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction")

Łukasz Dywicki
Hey MarkS,
The transaction manager you use can't do distributed transaction even if SQL Server providers xa compatible data source implementation.

If you are looking for XA then please take a look on Camel in Action samples (chapter 9 uses atomikos). In exampel configuration you will find how to wrap data sources and JMS connection factories.

Best regards,
Łukasz Dywicki
--
Code-House
http://code-house.org


Wiadomość napisana przez MarkS1900 w dniu 2012-01-26, o godz. 23:36:

>
> I have a Aries Blueprint file in my ServiceMix OSGi bundle, and I want to
> achieve JTA/XA transactions using the default ServiceMix 4.4.0
> ("features:install transaction").
>
> I am NOT using JPA, just raw JDBC calls.
>
> How do I register my Xa Jms ConnectionFactory
> (org.apache.activemq.ActiveMQXAConnectionFactory) and my Xa DataSource
> (com.microsoft.sqlserver.jdbc.MySQLServerXADataSource) with the container's
> transaction manager?
>
>
> <?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"
>>
>
>
>    <reference id="ariesTransactionManager"
> interface="javax.transaction.TransactionManager" />
>
>
>    <reference id="platformTransactionManager"
> interface="org.springframework.transaction.PlatformTransactionManager" />
>
> </blueprint>
>
>
>
> I am expecting working code to take the following form:
>
> --------  OPTION 1  --------
>
>
>    <bean id="transactionServiceBean"
> class="test.xa.service.TransactionServiceBean">
>        <property name="transactionManager" ref="platformTransactionManager"
> />
> <property name="persistenceHelper" ref="persistenceHelperXa" />
>    </bean>
>
> public class TransactionServiceBean
> {
>    //...
>
>    public void doTransactionCommit()
>    {
>
>        LOG.info( "doTransactionCommit() ->" );
>
>        TransactionStatus transactionStatus;
>
>        try
>        {
>            transactionStatus = transactionManager.getTransaction(
> transactionDefinition );
>
>        }
>        catch( Exception e )
>        {
>            LOG.error( "Transaction failed:  ", e );
>            return;
>        }
>
>        try
>        {
>    //  ...
>            //  DO JMS AND JDBC STUFF HERE
>    //  ...
>
>            transactionManager.commit( transactionStatus );
>
>        }
>        catch( Exception e1 )
>        {
>            LOG.error( "Commit failed:  ", e1 );
>
>            try
>            {
>                transactionManager.rollback( transactionStatus );
>            }
>            catch ( Exception e2 )
>            {
>                LOG.error( "Rollback failed:  ", e2 );
>                throw new RuntimeException( e2 );
>            }
>
>            throw new RuntimeException( e1 );
>        }
>
>        LOG.info( "doTransactionCommit() <-" );
>
>
>    }
>
>    // ...
> }
>
> --------  OPTION 2  --------
>
>
>    <bean id="transactionServiceBean"
> class="test.xa.service.TransactionServiceBean">
>        <tx:transaction method="do*" value="RequiresNew" />
>    </bean>
>
> public class TransactionServiceBean
> {
>    //...
>
>    public void doTransactionCommit()
>    {
>
>        LOG.info( "doTransactionCommit() ->" );
>
>        //  ...
>        //  DO JMS AND JDBC STUFF HERE
> //  ...
>
>        LOG.info( "doTransactionCommit() <-" );
>
>
>    }
>
>    // ...
> }
>
>
>
>
>
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/JTA-XA-transactions-using-the-default-ServiceMix-4-4-0-features-install-transaction-tp5434170p5434170.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction")

MarkS1900
Are you sure?  If this is true, what does the ServiceMix container transaction manager actually manage?


From what I understand, both services below point to the same service instance.  I did a toString on both and got the exact same toString value [org.apache.aries.transaction.GeronimoPlatformTransactionManager@1ed605b7].



<reference id="ariesTransactionManager" interface="javax.transaction.TransactionManager" />

<reference id="platformTransactionManager" interface="org.springframework.transaction.PlatformTransactionManager" />

The source of GeronimoPlatformTransactionManager:

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.aries.transaction/org.apache.aries.transaction.manager/0.3/org/apache/aries/transaction/GeronimoPlatformTransactionManager.java



Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction")

Łukasz Dywicki
Apache Geronimo uses same transaction manager but with tranql (JCA) which adopt multiple data sources (also non-xa) into managed connections which might be part of transaction.

I might be wrong, but I was unable to get proper XA with Aries/Geronimo Transaction Manager rollback on multiple data sources. I completed this with Atomikos.

Best regards,
Łukasz Dywicki
--
Code-House
http://code-house.org/


Wiadomość napisana przez MarkS1900 w dniu 2012-01-27, o godz. 17:46:

> Are you sure?  If this is true, what does the ServiceMix container
> transaction manager actually manage?
>
>
> From what I understand, both services below point to the same service
> instance.  I did a toString on both and got the exact same toString value
> [org.apache.aries.transaction.GeronimoPlatformTransactionManager@1ed605b7].
>
>
>
> <reference id="ariesTransactionManager"
> interface="javax.transaction.TransactionManager" />
>
> <reference id="platformTransactionManager"
> interface="org.springframework.transaction.PlatformTransactionManager" />
>
> The source of GeronimoPlatformTransactionManager:
>
> http://grepcode.com/file/repo1.maven.org/maven2/org.apache.aries.transaction/org.apache.aries.transaction.manager/0.3/org/apache/aries/transaction/GeronimoPlatformTransactionManager.java
>
>
>
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/JTA-XA-transactions-using-the-default-ServiceMix-4-4-0-features-install-transaction-tp5434170p5435965.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ("features:install transaction")

Guillaume Nodet
Administrator
The Geronimo TX manager is fully XA compliant and support 2PC without
any problems.
You won't be able to do real *distributed* transactions, meaning you
can't coordinate and pass along the transaction between several
containers, but a single container can handle any kind of XA
resources, be it a remote JDBC connection or a remote JMS broker.

2012/1/27 Łukasz Dywicki <[hidden email]>:

> Apache Geronimo uses same transaction manager but with tranql (JCA) which adopt multiple data sources (also non-xa) into managed connections which might be part of transaction.
>
> I might be wrong, but I was unable to get proper XA with Aries/Geronimo Transaction Manager rollback on multiple data sources. I completed this with Atomikos.
>
> Best regards,
> Łukasz Dywicki
> --
> Code-House
> http://code-house.org/
>
>
> Wiadomość napisana przez MarkS1900 w dniu 2012-01-27, o godz. 17:46:
>
>> Are you sure?  If this is true, what does the ServiceMix container
>> transaction manager actually manage?
>>
>>
>> From what I understand, both services below point to the same service
>> instance.  I did a toString on both and got the exact same toString value
>> [org.apache.aries.transaction.GeronimoPlatformTransactionManager@1ed605b7].
>>
>>
>>
>> <reference id="ariesTransactionManager"
>> interface="javax.transaction.TransactionManager" />
>>
>> <reference id="platformTransactionManager"
>> interface="org.springframework.transaction.PlatformTransactionManager" />
>>
>> The source of GeronimoPlatformTransactionManager:
>>
>> http://grepcode.com/file/repo1.maven.org/maven2/org.apache.aries.transaction/org.apache.aries.transaction.manager/0.3/org/apache/aries/transaction/GeronimoPlatformTransactionManager.java
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://servicemix.396122.n5.nabble.com/JTA-XA-transactions-using-the-default-ServiceMix-4-4-0-features-install-transaction-tp5434170p5435965.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>



--
------------------------
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
FuseSource, Integration everywhere
http://fusesource.com
Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ( with Atomikos )

MarkS1900
This post was updated on .
In reply to this post by MarkS1900
I think I managed to get JTA/XA transactions using the default ServiceMix 4.4.0 with Atomikos.

The example I created contains 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/f4b439bcb014/test-osgi-blueprint-xa-atomikos/src/main/resources/OSGI-INF/blueprint

README location:
test-osgi/test-osgi-blueprint-xa-atomikos/README.txt
Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ( with Atomikos )

Łukasz Dywicki
Hey Mark,
Your code is really clean and nice, that's really good start for others. I am happy that you managed XA to work.
However for one JMS and one JDBC resource you need only a local transaction. If the JDBC operation is in JMS transaction bounds you can rely on it. I am in middle of writing blog post about that.

Best regards,
Łukasz Dywicki
--
Code-House
http://code-house.org

Wiadomość napisana przez MarkS1900 w dniu 2012-01-28, o godz. 23:15:

> I think I managed to get JTA/XA transactions using the default ServiceMix
> 4.4.0 with Atomikos.
>
> The example I created contains 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
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/JTA-XA-transactions-using-the-default-ServiceMix-4-4-0-features-install-transaction-tp5434170p5438693.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: JTA/XA transactions using the default ServiceMix 4.4.0 ( with Atomikos )

MarkS1900
That type of blog post would be an interesting read.   Please provide a link once you have finished it.