Configure Grails using Spring

1,547 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,547
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Configure Grails using Spring

  1. 1. Configure Grails for JMSand JTA using Spring by Jonas BehmerPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  2. 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. 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 mappingPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  4. 4. Anatomy of a GrailsApp Where configuration hides Your domain will thrive here Transactional components The views Write the tests and prosperPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  5. 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. 6. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBossPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  7. 7. Setting up MessagingShopping 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.• TransactionManagerPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  8. 8. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBossPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  9. 9. Setting up JTA for distributed transactions• Spring handles transactions inGrails through aPlatformTransactionManager By default we have a• We need a GrailsHibernateTransactionManager JtaTransactionManager since we have both JMS and JDBC transactional resources• The JtaTransactionManager can The MessageListenerContainer weve 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. 10. Spring PlatformTransactionManager PlatformTransactionManager AbstractPlatformTransactionManagerJtaTransactionManager JmsTransactionManager JpaTransactionManager HibernateTransactionManager GrailsHibernateTransactionManager Class diagram of some the TransactionManager options offered by Spring PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  11. 11. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBossPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  12. 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 JNDIPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  13. 13. Todo! Create a MessageListener Create a container for the MessageListener Add a lookup to a JBoss TransactionManager Configure Hibernate Deploy to JBossPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
  14. 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.comPRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING

×