You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Scott Cote <sc...@etcc.com> on 2019/03/25 18:49:27 UTC

xa transaction manager and ignite

Igniters:

I'm unsuccessfully establishing an XA transaction manager to associate with my ignite configuration.

I don't know the JNDI name location of my java transaction manager (not to be confused with the spring transaction manager which implements TransactionManagerPlatform).

Here is a snippet of my code (with pieces omitted for brevity):

...

import javax.cache.configuration.Factory;
import javax.transaction.TransactionManager;

import org.apache.ignite.configuration.TransactionConfiguration;

import org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory;
...

@Autowired(required = false)
TransactionManager transactionManager;

...

private TransactionConfiguration doTransactionConfiguration() {
    TransactionConfiguration configuration = new TransactionConfiguration();

    if (null == transactionManager) {
        CacheJndiTmFactory txManagerFactory = new CacheJndiTmFactory();
        // see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html for these names
        String[] jndiNames = {"java:comp/UserTransaction","java:comp/TransactionManager","java:/TransactionManager"};
        txManagerFactory.setJndiNames(jndiNames);
        configuration.setTxManagerFactory(txManagerFactory);
    } else {

        Factory<TransactionManager> txManagerFactory = new Factory<TransactionManager>() {
            @Override
            public TransactionManager create() {
                return jtaTransactionManager();
            }
        };

        configuration.setTxManagerFactory(txManagerFactory);

    }
    return configuration;
}

private TransactionManager jtaTransactionManager() {
    return transactionManager;
}





public IgniteConfiguration doit() {

    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setTransactionConfiguration(doTransactionConfiguration());

    return cfg;

}

Here is a snippet of my code (with pieces omitted for brevity):
When I execute the public method "do it", the autowire fails to load (I do not require it) and none of the jndi locations that I listed seem to have the "java TransactionManager" (again - not to be confused with the bean named "TransactionManager" that does not implement TransactionManager, but instead implements TransactionManagerPlatform).

What is the right way to associate the xa manager that is setup with spring - which I don't know in advance, with ignite?

Thanks,

SCott

Re: xa transaction manager and ignite

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

Unfortunately I have no idea here. Maybe anyone more knowing will chime in.

Regards,
-- 
Ilya Kasnacheev


чт, 28 мар. 2019 г. в 00:37, Scott Cote <sc...@etcc.com>:

> Yes I did.  It is in fact the basis for my solution 😃
>
>
>
> Right now, I’m doing some fakery ….
>
>
>
> Taking the Spring JTATransactionManager (which extends
> AbstractTransactionManager which implements javax…TransactionManager) and
> wrapping it with an implementation of TransactionManager where the
> implementation stubs delegate to JTATransactionManager.
>
>
>
> The WrappedTransactionManager is then added to the ignite configuration.
>
>
>
> I hate this solution.
>
>
>
> Please tell me there is a better way.
>
>
>
> SCott
>
>
>
> *From:* Ilya Kasnacheev <il...@gmail.com>
> *Sent:* Wednesday, March 27, 2019 8:19 AM
> *To:* user@ignite.apache.org
> *Subject:* Re: xa transaction manager and ignite
>
>
>
> Hello!
>
>
>
> Never done that, but did you go through
> https://apacheignite.readme.io/docs/transactions#section-integration-with-jta
> ?
>
>
>
> Regards,
>
> --
>
> Ilya Kasnacheev
>
>
>
>
>
> пн, 25 мар. 2019 г. в 21:49, Scott Cote <sc...@etcc.com>:
>
> Igniters:
>
>
>
> I’m unsuccessfully establishing an XA transaction manager to associate
> with my ignite configuration.
>
>
>
> I don’t know the JNDI name location of my java transaction manager (not to
> be confused with the spring transaction manager which implements
> TransactionManagerPlatform).
>
>
>
> Here is a snippet of my code (with pieces omitted for brevity):
>
>
>
> …
>
> *import *javax.cache.configuration.Factory;
>
> *import *javax.transaction.TransactionManager;
>
> *import *org.apache.ignite.configuration.TransactionConfiguration;
>
> *import *org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory;
>
> …
>
> @Autowired(required = *false*)
> TransactionManager *transactionManager*;
>
>
>
> …
>
> *private *TransactionConfiguration doTransactionConfiguration() {
>     TransactionConfiguration configuration = *new *TransactionConfiguration();
>
>     *if *(*null *== *transactionManager*) {
>         CacheJndiTmFactory txManagerFactory = *new *CacheJndiTmFactory();
>
> *// see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html <https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html> for these names        *String[] jndiNames = {*"java:comp/UserTransaction"*,*"java:comp/TransactionManager"*,*"java:/TransactionManager"*};
>         txManagerFactory.setJndiNames(jndiNames);
>         configuration.setTxManagerFactory(txManagerFactory);
>     } *else *{
>
>         Factory<TransactionManager> txManagerFactory = *new *Factory<TransactionManager>() {
>             @Override
>             *public *TransactionManager create() {
>                 *return *jtaTransactionManager();
>             }
>         };
>
>         configuration.setTxManagerFactory(txManagerFactory);
>
>     }
>     *return *configuration;
> }
>
> *private *TransactionManager jtaTransactionManager() {
>     *return **transactionManager*;
> }
>
>
>
>
>
> *public *IgniteConfiguration doit() {
>
>     IgniteConfiguration cfg = *new *IgniteConfiguration();
>     cfg.setTransactionConfiguration(doTransactionConfiguration());
>
>     *return *cfg;
>
> }
>
>
>
> Here is a snippet of my code (with pieces omitted for brevity):
>
> When I execute the public method “do it”, the autowire fails to load (I do
> not require it) and none of the jndi locations that I listed seem to have
> the “java TransactionManager” (again – not to be confused with the bean
> named “TransactionManager” that does not implement TransactionManager, but
> instead implements TransactionManagerPlatform).
>
>
>
> What is the right way to associate the xa manager that is setup with
> spring – which I don’t know in advance, with ignite?
>
>
>
> Thanks,
>
>
>
> SCott
>
>

Re: xa transaction manager and ignite

Posted by Pavel Vinokurov <vi...@gmail.com>.
Hi Scott,

As I understand the issue is that Spring JTATransactionManager operates
primarily with* javax.transaction.UserTransaction* and optionally with
*javax.transaction.TransactionManager* for suspension and resumption
features.
The Ignite's transaction configuration requires exactly TransactionManager
that can be not accessible via jndi in some environments.
Actually many TransactionManager implementations  also implement
UserTransaction (or vice-versa). Thus you could try to obtain the
TransactionManager from the UserTransaction instance as presented below:

public TransactionManager getUserTransactionAsTransactionManager(){
    UserTransaction ut =
lookupJndiObject("java:comp/UserTransaction",UserTransaction.class);

    if(ut instanceof TransactionManager)
        return (TransactionManager)ut;

    return null;
}


Thanks,
Pavel

сб, 30 мар. 2019 г. в 09:49, Denis Magda <dm...@apache.org>:

> Hello Scott,
>
> Have you tried to return "new JTATransactionManager()"  from the
> implementation of the Factory as long as you know which class's instance is
> needed? The jndi-based approach is not necessary in this case.
> -
> Denis
>
>
> On Wed, Mar 27, 2019 at 2:37 PM Scott Cote <sc...@etcc.com> wrote:
>
>> Yes I did.  It is in fact the basis for my solution 😃
>>
>>
>>
>> Right now, I’m doing some fakery ….
>>
>>
>>
>> Taking the Spring JTATransactionManager (which extends
>> AbstractTransactionManager which implements javax…TransactionManager) and
>> wrapping it with an implementation of TransactionManager where the
>> implementation stubs delegate to JTATransactionManager.
>>
>>
>>
>> The WrappedTransactionManager is then added to the ignite configuration.
>>
>>
>>
>> I hate this solution.
>>
>>
>>
>> Please tell me there is a better way.
>>
>>
>>
>> SCott
>>
>>
>>
>> *From:* Ilya Kasnacheev <il...@gmail.com>
>> *Sent:* Wednesday, March 27, 2019 8:19 AM
>> *To:* user@ignite.apache.org
>> *Subject:* Re: xa transaction manager and ignite
>>
>>
>>
>> Hello!
>>
>>
>>
>> Never done that, but did you go through
>> https://apacheignite.readme.io/docs/transactions#section-integration-with-jta
>> ?
>>
>>
>>
>> Regards,
>>
>> --
>>
>> Ilya Kasnacheev
>>
>>
>>
>>
>>
>> пн, 25 мар. 2019 г. в 21:49, Scott Cote <sc...@etcc.com>:
>>
>> Igniters:
>>
>>
>>
>> I’m unsuccessfully establishing an XA transaction manager to associate
>> with my ignite configuration.
>>
>>
>>
>> I don’t know the JNDI name location of my java transaction manager (not
>> to be confused with the spring transaction manager which implements
>> TransactionManagerPlatform).
>>
>>
>>
>> Here is a snippet of my code (with pieces omitted for brevity):
>>
>>
>>
>> …
>>
>> *import *javax.cache.configuration.Factory;
>>
>> *import *javax.transaction.TransactionManager;
>>
>> *import *org.apache.ignite.configuration.TransactionConfiguration;
>>
>> *import *org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory;
>>
>> …
>>
>> @Autowired(required = *false*)
>> TransactionManager *transactionManager*;
>>
>>
>>
>> …
>>
>> *private *TransactionConfiguration doTransactionConfiguration() {
>>     TransactionConfiguration configuration = *new *TransactionConfiguration();
>>
>>     *if *(*null *== *transactionManager*) {
>>         CacheJndiTmFactory txManagerFactory = *new *CacheJndiTmFactory();
>>
>> *// see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html <https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html> for these names        *String[] jndiNames = {*"java:comp/UserTransaction"*,*"java:comp/TransactionManager"*,*"java:/TransactionManager"*};
>>         txManagerFactory.setJndiNames(jndiNames);
>>         configuration.setTxManagerFactory(txManagerFactory);
>>     } *else *{
>>
>>         Factory<TransactionManager> txManagerFactory = *new *Factory<TransactionManager>() {
>>             @Override
>>             *public *TransactionManager create() {
>>                 *return *jtaTransactionManager();
>>             }
>>         };
>>
>>         configuration.setTxManagerFactory(txManagerFactory);
>>
>>     }
>>     *return *configuration;
>> }
>>
>> *private *TransactionManager jtaTransactionManager() {
>>     *return **transactionManager*;
>> }
>>
>>
>>
>>
>>
>> *public *IgniteConfiguration doit() {
>>
>>     IgniteConfiguration cfg = *new *IgniteConfiguration();
>>     cfg.setTransactionConfiguration(doTransactionConfiguration());
>>
>>     *return *cfg;
>>
>> }
>>
>>
>>
>> Here is a snippet of my code (with pieces omitted for brevity):
>>
>> When I execute the public method “do it”, the autowire fails to load (I
>> do not require it) and none of the jndi locations that I listed seem to
>> have the “java TransactionManager” (again – not to be confused with the
>> bean named “TransactionManager” that does not implement TransactionManager,
>> but instead implements TransactionManagerPlatform).
>>
>>
>>
>> What is the right way to associate the xa manager that is setup with
>> spring – which I don’t know in advance, with ignite?
>>
>>
>>
>> Thanks,
>>
>>
>>
>> SCott
>>
>>

-- 

Regards

Pavel Vinokurov

Re: xa transaction manager and ignite

Posted by Denis Magda <dm...@apache.org>.
Hello Scott,

Have you tried to return "new JTATransactionManager()"  from the
implementation of the Factory as long as you know which class's instance is
needed? The jndi-based approach is not necessary in this case.
-
Denis


On Wed, Mar 27, 2019 at 2:37 PM Scott Cote <sc...@etcc.com> wrote:

> Yes I did.  It is in fact the basis for my solution 😃
>
>
>
> Right now, I’m doing some fakery ….
>
>
>
> Taking the Spring JTATransactionManager (which extends
> AbstractTransactionManager which implements javax…TransactionManager) and
> wrapping it with an implementation of TransactionManager where the
> implementation stubs delegate to JTATransactionManager.
>
>
>
> The WrappedTransactionManager is then added to the ignite configuration.
>
>
>
> I hate this solution.
>
>
>
> Please tell me there is a better way.
>
>
>
> SCott
>
>
>
> *From:* Ilya Kasnacheev <il...@gmail.com>
> *Sent:* Wednesday, March 27, 2019 8:19 AM
> *To:* user@ignite.apache.org
> *Subject:* Re: xa transaction manager and ignite
>
>
>
> Hello!
>
>
>
> Never done that, but did you go through
> https://apacheignite.readme.io/docs/transactions#section-integration-with-jta
> ?
>
>
>
> Regards,
>
> --
>
> Ilya Kasnacheev
>
>
>
>
>
> пн, 25 мар. 2019 г. в 21:49, Scott Cote <sc...@etcc.com>:
>
> Igniters:
>
>
>
> I’m unsuccessfully establishing an XA transaction manager to associate
> with my ignite configuration.
>
>
>
> I don’t know the JNDI name location of my java transaction manager (not to
> be confused with the spring transaction manager which implements
> TransactionManagerPlatform).
>
>
>
> Here is a snippet of my code (with pieces omitted for brevity):
>
>
>
> …
>
> *import *javax.cache.configuration.Factory;
>
> *import *javax.transaction.TransactionManager;
>
> *import *org.apache.ignite.configuration.TransactionConfiguration;
>
> *import *org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory;
>
> …
>
> @Autowired(required = *false*)
> TransactionManager *transactionManager*;
>
>
>
> …
>
> *private *TransactionConfiguration doTransactionConfiguration() {
>     TransactionConfiguration configuration = *new *TransactionConfiguration();
>
>     *if *(*null *== *transactionManager*) {
>         CacheJndiTmFactory txManagerFactory = *new *CacheJndiTmFactory();
>
> *// see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html <https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html> for these names        *String[] jndiNames = {*"java:comp/UserTransaction"*,*"java:comp/TransactionManager"*,*"java:/TransactionManager"*};
>         txManagerFactory.setJndiNames(jndiNames);
>         configuration.setTxManagerFactory(txManagerFactory);
>     } *else *{
>
>         Factory<TransactionManager> txManagerFactory = *new *Factory<TransactionManager>() {
>             @Override
>             *public *TransactionManager create() {
>                 *return *jtaTransactionManager();
>             }
>         };
>
>         configuration.setTxManagerFactory(txManagerFactory);
>
>     }
>     *return *configuration;
> }
>
> *private *TransactionManager jtaTransactionManager() {
>     *return **transactionManager*;
> }
>
>
>
>
>
> *public *IgniteConfiguration doit() {
>
>     IgniteConfiguration cfg = *new *IgniteConfiguration();
>     cfg.setTransactionConfiguration(doTransactionConfiguration());
>
>     *return *cfg;
>
> }
>
>
>
> Here is a snippet of my code (with pieces omitted for brevity):
>
> When I execute the public method “do it”, the autowire fails to load (I do
> not require it) and none of the jndi locations that I listed seem to have
> the “java TransactionManager” (again – not to be confused with the bean
> named “TransactionManager” that does not implement TransactionManager, but
> instead implements TransactionManagerPlatform).
>
>
>
> What is the right way to associate the xa manager that is setup with
> spring – which I don’t know in advance, with ignite?
>
>
>
> Thanks,
>
>
>
> SCott
>
>

RE: xa transaction manager and ignite

Posted by Scott Cote <sc...@etcc.com>.
Yes I did.  It is in fact the basis for my solution 😃

Right now, I’m doing some fakery ….

Taking the Spring JTATransactionManager (which extends AbstractTransactionManager which implements javax…TransactionManager) and wrapping it with an implementation of TransactionManager where the implementation stubs delegate to JTATransactionManager.

The WrappedTransactionManager is then added to the ignite configuration.

I hate this solution.

Please tell me there is a better way.

SCott

From: Ilya Kasnacheev <il...@gmail.com>
Sent: Wednesday, March 27, 2019 8:19 AM
To: user@ignite.apache.org
Subject: Re: xa transaction manager and ignite

Hello!

Never done that, but did you go through https://apacheignite.readme.io/docs/transactions#section-integration-with-jta ?

Regards,
--
Ilya Kasnacheev


пн, 25 мар. 2019 г. в 21:49, Scott Cote <sc...@etcc.com>>:
Igniters:

I’m unsuccessfully establishing an XA transaction manager to associate with my ignite configuration.

I don’t know the JNDI name location of my java transaction manager (not to be confused with the spring transaction manager which implements TransactionManagerPlatform).

Here is a snippet of my code (with pieces omitted for brevity):

…

import javax.cache.configuration.Factory;
import javax.transaction.TransactionManager;

import org.apache.ignite.configuration.TransactionConfiguration;

import org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory;
…

@Autowired(required = false)
TransactionManager transactionManager;

…

private TransactionConfiguration doTransactionConfiguration() {
    TransactionConfiguration configuration = new TransactionConfiguration();

    if (null == transactionManager) {
        CacheJndiTmFactory txManagerFactory = new CacheJndiTmFactory();
        // see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html for these names
        String[] jndiNames = {"java:comp/UserTransaction","java:comp/TransactionManager","java:/TransactionManager"};
        txManagerFactory.setJndiNames(jndiNames);
        configuration.setTxManagerFactory(txManagerFactory);
    } else {

        Factory<TransactionManager> txManagerFactory = new Factory<TransactionManager>() {
            @Override
            public TransactionManager create() {
                return jtaTransactionManager();
            }
        };

        configuration.setTxManagerFactory(txManagerFactory);

    }
    return configuration;
}

private TransactionManager jtaTransactionManager() {
    return transactionManager;
}





public IgniteConfiguration doit() {

    IgniteConfiguration cfg = new IgniteConfiguration();
    cfg.setTransactionConfiguration(doTransactionConfiguration());

    return cfg;

}

Here is a snippet of my code (with pieces omitted for brevity):
When I execute the public method “do it”, the autowire fails to load (I do not require it) and none of the jndi locations that I listed seem to have the “java TransactionManager” (again – not to be confused with the bean named “TransactionManager” that does not implement TransactionManager, but instead implements TransactionManagerPlatform).

What is the right way to associate the xa manager that is setup with spring – which I don’t know in advance, with ignite?

Thanks,

SCott

Re: xa transaction manager and ignite

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

Never done that, but did you go through
https://apacheignite.readme.io/docs/transactions#section-integration-with-jta
?

Regards,
-- 
Ilya Kasnacheev


пн, 25 мар. 2019 г. в 21:49, Scott Cote <sc...@etcc.com>:

> Igniters:
>
>
>
> I’m unsuccessfully establishing an XA transaction manager to associate
> with my ignite configuration.
>
>
>
> I don’t know the JNDI name location of my java transaction manager (not to
> be confused with the spring transaction manager which implements
> TransactionManagerPlatform).
>
>
>
> Here is a snippet of my code (with pieces omitted for brevity):
>
>
>
> …
>
> *import *javax.cache.configuration.Factory;
>
> *import *javax.transaction.TransactionManager;
>
> *import *org.apache.ignite.configuration.TransactionConfiguration;
>
> *import *org.apache.ignite.cache.jta.jndi.CacheJndiTmFactory;
>
> …
>
> @Autowired(required = *false*)
> TransactionManager *transactionManager*;
>
>
>
> …
>
> *private *TransactionConfiguration doTransactionConfiguration() {
>     TransactionConfiguration configuration = *new *TransactionConfiguration();
>
>     *if *(*null *== *transactionManager*) {
>         CacheJndiTmFactory txManagerFactory = *new *CacheJndiTmFactory();
>
> *// see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html <https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html> for these names        *String[] jndiNames = {*"java:comp/UserTransaction"*,*"java:comp/TransactionManager"*,*"java:/TransactionManager"*};
>         txManagerFactory.setJndiNames(jndiNames);
>         configuration.setTxManagerFactory(txManagerFactory);
>     } *else *{
>
>         Factory<TransactionManager> txManagerFactory = *new *Factory<TransactionManager>() {
>             @Override
>             *public *TransactionManager create() {
>                 *return *jtaTransactionManager();
>             }
>         };
>
>         configuration.setTxManagerFactory(txManagerFactory);
>
>     }
>     *return *configuration;
> }
>
> *private *TransactionManager jtaTransactionManager() {
>     *return **transactionManager*;
> }
>
>
>
>
>
> *public *IgniteConfiguration doit() {
>
>     IgniteConfiguration cfg = *new *IgniteConfiguration();
>     cfg.setTransactionConfiguration(doTransactionConfiguration());
>
>     *return *cfg;
>
> }
>
>
>
> Here is a snippet of my code (with pieces omitted for brevity):
>
> When I execute the public method “do it”, the autowire fails to load (I do
> not require it) and none of the jndi locations that I listed seem to have
> the “java TransactionManager” (again – not to be confused with the bean
> named “TransactionManager” that does not implement TransactionManager, but
> instead implements TransactionManagerPlatform).
>
>
>
> What is the right way to associate the xa manager that is setup with
> spring – which I don’t know in advance, with ignite?
>
>
>
> Thanks,
>
>
>
> SCott
>