SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Configure Grails for JMS
and JTA using Spring
                         by Jonas Behmer




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
The question


     Is it possible to use Grails for my new killer app
     that needs all the JEE-stack integration stuff
     with distributed transactions on top of it?




                            YES OF COURSE!




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Grails in two minutes
     •   Philosophy

           • Convention over configuration (sensible defaults)
           • Dynamic and flexible
           • Builds on existing technologies with a plethora of plugins
     •   Technology

           • Groovy
               • Dynamic programming for the JVM
           • Spring
               • Grails is a Spring MVC in disguise
               • CoC is powered by dependency injection
           • Hibernate
               • Object to Relational db mapping
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Anatomy of a GrailsApp


                                                  Where configuration
                                                  hides


                                                  Your domain will
                                                  thrive here

                                                  Transactional
                                                  components



                                                  The views


                                                  Write the tests
                                                  and prosper


PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
The scenario

•   We have more than one transactional resource (both JDBC and
    JMS)

•   And we want JBoss to coordinate all the transactions for all of our
    transactional resources.




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Todo!
    Create a MessageListener

    Create a container for the MessageListener

    Add a lookup to a JBoss TransactionManager

    Configure Hibernate

    Deploy to JBoss




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Setting up Messaging
Shopping list:                                  Lots of options in Spring:
                                                SimpleMessageListenerContainer,
•   Some kind of Message Listener               DefaultMessageListenerContainer
    Container that is JEE compatible            or a JCA-based MessageListener
                                                container.
•   A javax.jms.MessageListener

•   A javax.jms.ConnectionFactory
                                                 Note!!!
    to create connections to the JMS
                                                 We could take a short cut
    provider                                     and just install the JMS-Plugin
                                                 for Grails which uses as Default-
•   Destination
                                                 MessageListenerContainer behind
                                                 the curtains.
•   TransactionManager



PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Todo!
    Create a MessageListener

    Create a container for the MessageListener

    Add a lookup to a JBoss TransactionManager

    Configure Hibernate

    Deploy to JBoss




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Setting up JTA for distributed transactions

• Spring handles transactions in
Grails through a
PlatformTransactionManager
                                                By default we have a
•   We need a
                                                GrailsHibernateTransactionManager
    JtaTransactionManager since we
    have both JMS and JDBC
    transactional resources

•   The JtaTransactionManager can                  The MessageListenerContainer we've
    lookup the TransactionManager                  setup will also use this

    in JBoss through JNDI and                      TransactionManager

    delegate all the work!


PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Spring PlatformTransactionManager
                                         PlatformTransactionManager




                                      AbstractPlatformTransactionManager




JtaTransactionManager                                                         JmsTransactionManager


                                                           JpaTransactionManager
                        HibernateTransactionManager




                 GrailsHibernateTransactionManager




       Class diagram of some the TransactionManager
       options offered by Spring


       PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Todo!
    Create a MessageListener

    Create a container for the MessageListener

    Add a lookup to a JBoss TransactionManager

    Configure Hibernate

    Deploy to JBoss




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Configure Hibernate

    •   The last bit remaining is tying it all up in Hibernate

    •   Must know that we want to use transactions through JTA

          •   hibernate.transaction.factory_class =
              org.hibernate.transaction.JTATransactionFactory

    •   Must be made aware of the fact that JBoss coordinates the
        transactions:

          •   hibernate.transaction.manager_lookup_class =
              'org.hibernate.transaction.JBossTransactionManagerLookup'

    •   Lookup a XA compliant datasource in Jboss through JNDI




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Todo!
    Create a MessageListener

    Create a container for the MessageListener

    Add a lookup to a JBoss TransactionManager

    Configure Hibernate

    Deploy to JBoss




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Where to go from here?
•   Clone my git repo

     •   git clone https://github.com/jonasbehmer/vehicleposition.git

•   Buy the books

     •   The Definitive guide to Grails (2nd edition)

     •   Groovy in Action (2nd edition this summer)

•   Mail a consultant

     •   jonas.behmer@redpill-linpro.com




PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING

Más contenido relacionado

La actualidad más candente

Social Connections II - Paul Mason - Applicable, the power of choice
Social Connections II - Paul Mason - Applicable, the power of choiceSocial Connections II - Paul Mason - Applicable, the power of choice
Social Connections II - Paul Mason - Applicable, the power of choice
Stuart McIntyre
 
Cloud Hosting for Government Agencies: Drupal Platform as a Service
Cloud Hosting for Government Agencies: Drupal Platform as a ServiceCloud Hosting for Government Agencies: Drupal Platform as a Service
Cloud Hosting for Government Agencies: Drupal Platform as a Service
Acquia
 

La actualidad más candente (8)

Social Connections II - Paul Mason - Applicable, the power of choice
Social Connections II - Paul Mason - Applicable, the power of choiceSocial Connections II - Paul Mason - Applicable, the power of choice
Social Connections II - Paul Mason - Applicable, the power of choice
 
Adaptive Computing Using PlateSpin Orchestrate
Adaptive Computing Using PlateSpin OrchestrateAdaptive Computing Using PlateSpin Orchestrate
Adaptive Computing Using PlateSpin Orchestrate
 
Managed services overview
Managed services overviewManaged services overview
Managed services overview
 
Integrating Novell Teaming within Your Existing Infrastructure
Integrating Novell Teaming within Your Existing InfrastructureIntegrating Novell Teaming within Your Existing Infrastructure
Integrating Novell Teaming within Your Existing Infrastructure
 
Becoming Software Oriented in a Solutions Centric Industry
Becoming Software Oriented in a Solutions Centric IndustryBecoming Software Oriented in a Solutions Centric Industry
Becoming Software Oriented in a Solutions Centric Industry
 
Kognitio overview april 2013
Kognitio overview april 2013Kognitio overview april 2013
Kognitio overview april 2013
 
Is Private Cloud Right for Your Organization
Is Private Cloud Right for Your OrganizationIs Private Cloud Right for Your Organization
Is Private Cloud Right for Your Organization
 
Cloud Hosting for Government Agencies: Drupal Platform as a Service
Cloud Hosting for Government Agencies: Drupal Platform as a ServiceCloud Hosting for Government Agencies: Drupal Platform as a Service
Cloud Hosting for Government Agencies: Drupal Platform as a Service
 

Destacado (9)

Spring Framework - Validation
Spring Framework - ValidationSpring Framework - Validation
Spring Framework - Validation
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Spring Framework - Expression Language
Spring Framework - Expression LanguageSpring Framework - Expression Language
Spring Framework - Expression Language
 
Spring Framework - Web Flow
Spring Framework - Web FlowSpring Framework - Web Flow
Spring Framework - Web Flow
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data Access
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Spring Framework - MVC
Spring Framework - MVCSpring Framework - MVC
Spring Framework - MVC
 
Spring Framework - Spring Security
Spring Framework - Spring SecuritySpring Framework - Spring Security
Spring Framework - Spring Security
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 

Similar a Configure Grails using Spring

Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
Markus Eisele
 
Datasheet was pluginforrd
Datasheet was pluginforrdDatasheet was pluginforrd
Datasheet was pluginforrd
MidVision
 
Datasheet j bosspluginforrd
Datasheet j bosspluginforrdDatasheet j bosspluginforrd
Datasheet j bosspluginforrd
MidVision
 
Datasheet weblogicpluginforrd
Datasheet weblogicpluginforrdDatasheet weblogicpluginforrd
Datasheet weblogicpluginforrd
MidVision
 
Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352
sflynn073
 
Datasheet j boss-midvisionextensionforibmraf
Datasheet j boss-midvisionextensionforibmrafDatasheet j boss-midvisionextensionforibmraf
Datasheet j boss-midvisionextensionforibmraf
MidVision
 
DrupalCamp ATL 2010: Not all CMSs are created equal
DrupalCamp ATL 2010: Not all CMSs are created equalDrupalCamp ATL 2010: Not all CMSs are created equal
DrupalCamp ATL 2010: Not all CMSs are created equal
andrewmriley
 
An Introduction To Palomino
An Introduction To PalominoAn Introduction To Palomino
An Introduction To Palomino
Laine Campbell
 
Datasheet weblogic midvisionextensionforibmraf
Datasheet weblogic midvisionextensionforibmrafDatasheet weblogic midvisionextensionforibmraf
Datasheet weblogic midvisionextensionforibmraf
MidVision
 

Similar a Configure Grails using Spring (20)

Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
Datasheet was pluginforrd
Datasheet was pluginforrdDatasheet was pluginforrd
Datasheet was pluginforrd
 
Transactions
TransactionsTransactions
Transactions
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012
 
Succeding with the Apache SOA stack
Succeding with the Apache SOA stackSucceding with the Apache SOA stack
Succeding with the Apache SOA stack
 
Datasheet j bosspluginforrd
Datasheet j bosspluginforrdDatasheet j bosspluginforrd
Datasheet j bosspluginforrd
 
Datasheet weblogicpluginforrd
Datasheet weblogicpluginforrdDatasheet weblogicpluginforrd
Datasheet weblogicpluginforrd
 
Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352
 
Datasheet j boss-midvisionextensionforibmraf
Datasheet j boss-midvisionextensionforibmrafDatasheet j boss-midvisionextensionforibmraf
Datasheet j boss-midvisionextensionforibmraf
 
DrupalCamp ATL 2010: Not all CMSs are created equal
DrupalCamp ATL 2010: Not all CMSs are created equalDrupalCamp ATL 2010: Not all CMSs are created equal
DrupalCamp ATL 2010: Not all CMSs are created equal
 
An Introduction To Palomino
An Introduction To PalominoAn Introduction To Palomino
An Introduction To Palomino
 
DevOps Cardiff - Monitoring Automation for DevOps
DevOps Cardiff - Monitoring Automation for DevOpsDevOps Cardiff - Monitoring Automation for DevOps
DevOps Cardiff - Monitoring Automation for DevOps
 
Resume
ResumeResume
Resume
 
Intro to Drools - St Louis Gateway JUG
Intro to Drools - St Louis Gateway JUGIntro to Drools - St Louis Gateway JUG
Intro to Drools - St Louis Gateway JUG
 
Foresight
ForesightForesight
Foresight
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 
Angular + JHipster - JHipster Conf
Angular + JHipster - JHipster ConfAngular + JHipster - JHipster Conf
Angular + JHipster - JHipster Conf
 
Genexus - part 3 - process management
Genexus - part 3 - process managementGenexus - part 3 - process management
Genexus - part 3 - process management
 
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
Plugin-able POS Solutions by Javascript @HDM9 TaiwanPlugin-able POS Solutions by Javascript @HDM9 Taiwan
Plugin-able POS Solutions by Javascript @HDM9 Taiwan
 
Datasheet weblogic midvisionextensionforibmraf
Datasheet weblogic midvisionextensionforibmrafDatasheet weblogic midvisionextensionforibmraf
Datasheet weblogic midvisionextensionforibmraf
 

Configure Grails using Spring

  • 1. Configure Grails for JMS and JTA using Spring by Jonas Behmer PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 2. The question Is it possible to use Grails for my new killer app that needs all the JEE-stack integration stuff with distributed transactions on top of it? YES OF COURSE! PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 3. Grails in two minutes • Philosophy • Convention over configuration (sensible defaults) • Dynamic and flexible • Builds on existing technologies with a plethora of plugins • Technology • Groovy • Dynamic programming for the JVM • Spring • Grails is a Spring MVC in disguise • CoC is powered by dependency injection • Hibernate • Object to Relational db mapping PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 4. Anatomy of a GrailsApp Where configuration hides Your domain will thrive here Transactional components The views Write the tests and prosper PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 5. The scenario • We have more than one transactional resource (both JDBC and JMS) • And we want JBoss to coordinate all the transactions for all of our transactional resources. PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 6. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBoss PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 7. Setting up Messaging Shopping list: Lots of options in Spring: SimpleMessageListenerContainer, • Some kind of Message Listener DefaultMessageListenerContainer Container that is JEE compatible or a JCA-based MessageListener container. • A javax.jms.MessageListener • A javax.jms.ConnectionFactory Note!!! to create connections to the JMS We could take a short cut provider and just install the JMS-Plugin for Grails which uses as Default- • Destination MessageListenerContainer behind the curtains. • TransactionManager PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 8. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBoss PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 9. Setting up JTA for distributed transactions • Spring handles transactions in Grails through a PlatformTransactionManager By default we have a • We need a GrailsHibernateTransactionManager JtaTransactionManager since we have both JMS and JDBC transactional resources • The JtaTransactionManager can The MessageListenerContainer we've lookup the TransactionManager setup will also use this in JBoss through JNDI and TransactionManager delegate all the work! PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 10. Spring PlatformTransactionManager PlatformTransactionManager AbstractPlatformTransactionManager JtaTransactionManager JmsTransactionManager JpaTransactionManager HibernateTransactionManager GrailsHibernateTransactionManager Class diagram of some the TransactionManager options offered by Spring PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 11. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBoss PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 12. Configure Hibernate • The last bit remaining is tying it all up in Hibernate • Must know that we want to use transactions through JTA • hibernate.transaction.factory_class = org.hibernate.transaction.JTATransactionFactory • Must be made aware of the fact that JBoss coordinates the transactions: • hibernate.transaction.manager_lookup_class = 'org.hibernate.transaction.JBossTransactionManagerLookup' • Lookup a XA compliant datasource in Jboss through JNDI PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 13. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBoss PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  • 14. Where to go from here? • Clone my git repo • git clone https://github.com/jonasbehmer/vehicleposition.git • Buy the books • The Definitive guide to Grails (2nd edition) • Groovy in Action (2nd edition this summer) • Mail a consultant • jonas.behmer@redpill-linpro.com PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING