geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: client managed distributed transactions
Date Tue, 12 May 2009 23:07:58 GMT

On May 12, 2009, at 2:52 PM, munguia wrote:

>
> Hi David,
>
> Thanks for your reply, let me explain in more detail the  
> architecture I'm
> currently dealing with.
>
> I have three spring independent applications and I have a fourth  
> application
> that need to invoke services on the other three (use them as a back- 
> end if
> you like).
>
> This fourth application was communicating with the other three by  
> means of
> RESTful web services, this worked pretty good until we got to a  
> point where
> a single service method in the 4th app needed to invoke a service  
> method on
> the 1st and 2nd apps, so if the call to the 1st method succeeded but  
> the
> call to the 2nd app failed then the whole setup will end up being in  
> an
> inconsistent state.
>
> I didn't find a solution for transactional RESTful web services, so I
> decided to try an scenario where the services on the 1st, 2nd and  
> 3rd apps
> were exposed as stateless session beans. So it looks something like  
> this
> (just for the 1sp app):
>
> VM{4th Spring App} <------> VM{Geronimo EJBs exposing 1st Spring App}
>
> So basically we're talking about sharing a single transaction  
> between, at
> least, two different VMs. The idea will be to have the 4th app  
> starting, an
> controllling, the tx and have the other apps attaching to this tx  
> (by means
> of the REQUIRED annotation and some voodoo transaction sharing  
> strategy =]
> ).

This multi-vm setup is not supported out of the box by geronimo.   
You'll have to do something like write an inbound resource adapter.
>
>
> The configuration I did before had an scenario where all the action  
> happened
> inside a single VM. To answer your question the UserTransaction was  
> just a
> mock bean managed by Spring's mock JNDI functionality. I successfully
> managed to share a single transaction between the two datasources  
> (MySQL and
> JCR).

If you can manage to run all 4 apps in the same vm, perhaps on lots of  
identical servers, your life will be a _lot_ easier and the app will  
almost certainly run a lot faster.

>
>
> Where can I find resources explaining how to import the transaction  
> into
> Geronimo (using j2ca)?

The only resources I know of are the j2ca 1.5 spec.  I don't know of  
any resource adapter that actually use this feature.  It may be easier  
to extend the openejb proprietary protocol to handle sending xids over  
the wire and not write a whole resource adapter.

Either way, for the client side you'll need to implement an XAResource  
and something to register it with the tm when you try to do work in a  
tx.  Then the communication will have to send the (branch) xid from  
the xaresource in the appropriate messages. You'll need special  
prepare/commit/rollback messages

On the server side, youll have to get the xids out of the messages.   
If you decide to use a J2ca adapter, you can use the WorkManager and  
set the xid in the import context.  In this case you'll probably want  
to convert your session beans to be message driven beans (they can  
keep whatever interface they have now, they don't need to be a jms  
MessageListener)  If you extend the openejb protocol directly you'll  
end up doing something similar but may want to use the proprietary  
geronimo tm XAWork interface rather than the WorkManager from j2ca.

I think this is a non-trivial project.... which is the main reason I  
haven't tried doing it myself several years ago.  It would be really  
great to have the code in either geronimo or openejb if you do work on  
it and can contribute the result.

You could also implement the corba tx interoperablilty but that is  
likely to be even trickier because not only do you have to figure out  
what is needed to make it work, you have to figure out how corba  
thinks it needs to be done as well.

hope this helps and is not too discouraging :-)

You might also consider if you really need this all to be done  
synchronously or if you can divide it up into a bunch of asynchoronous  
steps each done in a jms transaction.

thanks
david jencks

>
>
> Thanks!
> Diego
>
>
> djencks wrote:
>>
>>
>> On May 8, 2009, at 4:20 PM, Diego Munguia wrote:
>>
>>> Hi,
>>>
>>> I have a spring-based application that connects to a local database
>>> and to a set of remote EJBs that are deployed on a Geronimo 2.1.4
>>> server. I'm trying to configure a transaction manager that handles
>>> distributed transactions, because on a single service method I may
>>> have calls to the local db and to one or more EJBs (stateless
>>> session beans).
>>
>> I don't understand your configuration.  Is the spring app running in
>> the same geronimo 2.1.4 instance as the ejbs?  If so I suspect you
>> don't need to do anything so long as your ejbs are not configured to
>> start new txs.  You might possibly need to use a local ejb interface,
>> but I doubt it.
>>
>> If your spring app is running in a different jvm than geronimo, you
>> will have to do some serious coding to get this to work.  Although
>> geronimo does support importing transactions through the j2ca work
>> manager stuff, we don't have a full distributed transaction
>> implementation.
>>
>> Be sure you understand the difference between 2-phase multi-resource
>> xa transactions that occur entirely in one vm (at least all the
>> XAResource implementations are in the same vm) and a true distributed
>> transaction in which XAResources are present in several vms; in a
>> typical xa implementation of a distributed tx system you'll have at
>> least two app server instances, one server will control the tx, and
>> all the other servers will be represented as XAResources to the
>> controlling server.
>>
>> So far I've never found anyone who thinks using distributed
>> transactions in a production system is plausible if there is any kind
>> of load involved.  This has driven our lack of implementation.
>>
>>>
>>>
>>> I've managed to configure distributed transactions in the past using
>>> Jencks and the Geronimo TM but for local datasources (1 mysql db and
>>> 1 jackrabbit repository), this configuration required the use of a
>>> UserTransaction object, I used spring's jndi mock functionality as I
>>> wasn't using a j2ee server.
>> ??? Where did the UserTransaction come from
>>>
>>>
>>> I'm trying to replicate this conf on my current app but my problem
>>> is that I can't get a hold of the remote UserTransaction object via
>>> jndi. This is how I'm trying to retrieve it:
>>>
>>>       Properties properties = new Properties();
>>>       properties.put(Context.INITIAL_CONTEXT_FACTORY,
>>> "org.apache.openejb.client.RemoteInitialContextFactory");
>>>       properties.put("java.naming.provider.url", "ejbd://localhost:
>>> 4201");
>>>       Context context = new InitialContext(properties);
>>>       context.lookup("java:comp/UserTransaction");
>>>
>>> I'm getting this exception:
>>>
>>> Exception in thread "main" javax.naming.NameNotFoundException: comp/
>>> UserTransaction does not exist in the system.  Check that the app
>>> was successfully deployed.
>>> 	at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java: 
>>> 277)
>>> 	at javax.naming.InitialContext.lookup(InitialContext.java:351)
>>
>>
>> I don't understand what you want to use the UserTransaction for.  To
>> control the entire jta tx or to control the ejb's participation in  
>> the
>> tx?
>>
>> If the latter, even if this appeared to work, it wouldn't give you a
>> transaction.  UserTransaction doesn't support the 2 phase commit
>> process you need for a multi-resource transaction.  IIRC spring
>> doesn't make much effort to point this out.
>>
>>>
>>>
>>>
>>> If I go to the Geronimo console and look for UserTransaction using
>>> the JNDI Viewer I see that there is an user transaction object under
>>> the name java:comp/UserTransaction, so I'm guessing I'm using the
>>> correct jndi name on my code. Plus the app successfully retrieves
>>> the ejb proxies so I know the jndi service is up and running.
>>>
>>> How can I retrieve the user transaction then? If there's a reason
>>> why the user transaction is not provided for remote clients then
>>> does anybody knows of an alternative strategy to do client-managed
>>> transactions or any other kind of distributed transactions strategy
>>> that allows me to keep track of my local db changes as well the ejbs
>>> on the same transaction?
>>
>> If the ejbs are on a different vm than your spring program I'd advise
>> you to rethink your architecture.  If you really need them on
>> different machines make the communication asynchronous using jms.
>>
>> thanks
>> david jencks
>>
>>>
>>>
>>> Thanks!
>>> - Diego M.
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/client-managed-distributed-transactions-tp23455243s134p23511296.html
> Sent from the Apache Geronimo - Users mailing list archive at  
> Nabble.com.
>


Mime
View raw message