11 Replies Latest reply: Jun 11, 2014 7:00 AM by Tom Jenkinson RSS

Narayana and Spring with multiple JVM

Dinesh J. Weerakkody Newbie

Hi,

 

I'm developing a distributed web application with spring and hibernate. First of all let me explain the basic structure of the application.

 

Environment

We have 3 JEE web projects (.war),

1) Web UI

2) Purchase related service (back-end application)

3) Payment related service (back-end application)

All these applications are running in 3 different tomcat servers in 3 physical servers. Development database is PostgreSQL and Oracle 11G as live DB.

 

Scenario

When user enter new purchase details to the system I want to create a payment record too. Purchase record should handled by purchase back-end and payment should handled by the payment back-end. Currently everything works fine without the transaction handling part.

 

Problem

If something goes wrong in the payment back-end, purchase record also should be rollback. What is the best way to handle these distributed transactions. Can I use Narayana-JTS standalone version to fulfill my requirement. Can someone suggest a method and sample spring configuration code snippets.

 

Note

I prefer a method without JBossAS, because my applications are lightweight and no need any AS features up-to now.

 

Thanks.

  • 1. Re: Narayana and Spring with multiple JVM
    Tom Jenkinson Master

    Hi Dinesh,

     

    Thanks for your interest in Narayana!

     

    I understand your scenario and what I would say is that moving to remote EJB invocations inside WildFly AS is probably going to be easiest for you. You certainly can run JTS in standalone mode and we do have a documentation set for this on narayana.io. We also have a quickstart that can be used standalone: https://github.com/jbosstm/quickstart/tree/master/ArjunaJTS/trailmap . Now, I haven't looked through that QS for years but it should still apply. If you were in a position to use WildFly I can recommend using this quickstart instead: https://github.com/jboss-developer/jboss-eap-quickstarts/tree/6.3.x-develop/jts


    Take a look at them both and have a think of which application you would prefer to build.


    Hope it helps,

    Tom

  • 2. Re: Narayana and Spring with multiple JVM
    Dinesh J. Weerakkody Newbie

    Dear Tom,

     

    Thank you very much for your quick reply. We can use WildFly AS but will not be able to use EJB because we have finished most of the development using Hibernate. Anyway I'll go through the documents and get back to you soon.

     

    Thanks again..

  • 3. Re: Re: Narayana and Spring with multiple JVM
    Tom Jenkinson Master

    No problem.

     

    I would add a small EJB between the existing app and existing clients to propagate the transport.

     

    Whatever approach you take you will need to write some more code, I suspect the EJB code would be smaller in comparison to the alternative but I may be wrong.

     

    There are alternative methods of propagating the transaction, we have a webservices transport and a REST one. Let me know if you think these might help. There should be quickstarts for these in https://github.com/jbosstm/quickstart/

     

    Tom

  • 4. Re: Narayana and Spring with multiple JVM
    Damiano Pezzotti Newbie

    Hi Tom,

    Do you have an example on transaction propagation using REST?

    We have a similar problem. 2 applications on different war files that communicate via hessian protocol (based on HTTP, then very similar to REST) and we are trying to create a global transaction across the 2 applications.

     

    Thanks

    Damiano

  • 5. Re: Narayana and Spring with multiple JVM
    Tom Jenkinson Master

    Hi Damiano,

     

    You could take a look at our RTS quickstarts over here: https://github.com/jbosstm/quickstart/tree/master/rts

     

    Tom

  • 6. Re: Narayana and Spring with multiple JVM
    Damiano Pezzotti Newbie

    Hi Tom,

    thanks for your response.

    I'm not sure that your link solves my problem, then I try to describe it with more details.

     

    We have 2 applications packaged as war running on JBoss 7.1.1.

    These applications uses Spring and JPA and communicate each other using Spring Remoting (using Hessian Protocol).

    The first application start the transaction and writes data on db1.

    Then it calls a service exposed via Hessian protocol by the second application. This service writes data on db2 and then returns control to the first application.

    The first application writes data on db1.

    If this operation fails, I want to rollback the entire transaction.

     

    Is it possible to using JBossTM for this scenario?

  • 7. Re: Narayana and Spring with multiple JVM
    Tom Jenkinson Master

    Hi Damiano,

     

    Ah, I thought you were asking after REST examples. We don't have a hessian transport for JBossTM out of the box. Is there a transaction API for hessian do you know? The core of JBossTM is a pluggable architecture and we have support for many transports: JTS/SOAP/REST/JBoss Remoting. If there is some way to integrate hessian with REST stuff it might work.

     

    Tom

  • 8. Re: Narayana and Spring with multiple JVM
    Damiano Pezzotti Newbie

    Hi Tom,

    Unfortunately hessian doesn't support transactions out-of-the-box, but we'd like to try to implement the mechanism (hessian is based on HTTP).

    The idea is to start the transaction on the first application and then propagate it using the remote hessian call.

    If application one or application two has an error, the entire transaction is rolled back.

     

    Do you think it is possible? If yes, how can I propagate the transaction? Is it possible to pass a sort of transactionId using an HTTP header?

     

    Thanks

    Damiano

  • 9. Re: Narayana and Spring with multiple JVM
    Tom Jenkinson Master

    Hi Damiano,

     

    It should certainly be possible but its not supported out of the box and would required you to write the transport adaptors. One of the best examples of this would probably be the way that the JBoss Remoting transport was written. You could take that as a template. They basically register as an XAResource and then serialize and ship the Xids around and respond to the transaction managers XAResource invocations. Special consideration is required at recovery.

     

    You can see the way they integrate with the recovery manager here (look at the recover() method: https://github.com/jbossas/jboss-ejb-client/blob/master/src/main/java/org/jboss/ejb/client/RecoveryOnlyEJBXAResource.java)

     

    You could also use RTS as a start point, but if you have XA calls already it might be easiest to just sit behind the XAResource interface.

     

    Hope it helps,

    Tom

  • 10. Re: Narayana and Spring with multiple JVM
    Damiano Pezzotti Newbie

    Hi Tom,

    Thanks for your support.

    I think that JBoss Remoting could be a similar scenario for me.

    Where can I find code for remoting/jbosstm integration?

     

    Regards

    Damiano

  • 11. Re: Narayana and Spring with multiple JVM
    Tom Jenkinson Master

    Hi Damiano,

     

    It's in that repo I linked to above. Clone the repo and look for the XAResource implementations, iirc there are two, one for recovery and one for normal usage. Once you have found the XAR it should be relatively straightforward to see how the propagation is done for JBoss Remoting. The next thing is to see how the XAR are registered with the transaction manager. The recovery one is straight forward, the one that is registered when the transaction propagates is a bit more complex and would be the toughest bit for you to implement I suspect. With your application you will need to register a hook that anytime it propagates to another server you need to hook in an XAResource if its not already enlist for that TX at that server pair.

     

    Tom