configure grails using spring
TRANSCRIPT
![Page 1: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/1.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Configure Grails for JMS and JTA using Spring
by Jonas Behmer
![Page 2: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/2.jpg)
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 stuffwith distributed transactions on top of it?
YES OF COURSE!
![Page 3: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/3.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
• 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
Grails in two minutes
![Page 4: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/4.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Anatomy of a GrailsApp
Where configuration hides
Your domain will thrive hereTransactional components
The views
Write the tests and prosper
![Page 5: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/5.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
• 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.
The scenario
![Page 6: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/6.jpg)
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
![Page 7: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/7.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Setting up MessagingShopping list:
• Some kind of Message Listener Container that is JEE compatible
• A javax.jms.MessageListener
• A javax.jms.ConnectionFactory to create connections to the JMS provider
• Destination
• TransactionManager
Lots of options in Spring:SimpleMessageListenerContainer,DefaultMessageListenerContaineror a JCA-based MessageListener container.
Note!!!We could take a short cutand just install the JMS-Pluginfor Grails which uses as Default-MessageListenerContainer behindthe curtains.
![Page 8: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/8.jpg)
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
![Page 9: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/9.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Setting up JTA for distributed transactions
• Spring handles transactions in Grails through a PlatformTransactionManager
• We need a JtaTransactionManager since we have both JMS and JDBC transactional resources
• The JtaTransactionManager can lookup the TransactionManager in JBoss through JNDI and delegate all the work!
By default we have a GrailsHibernateTransactionManager
The MessageListenerContainer we've setup will also use this TransactionManager
![Page 10: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/10.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
Spring PlatformTransactionManager
Class diagram of some the TransactionManager options offered by Spring
AbstractPlatformTransactionManager
HibernateTransactionManager
JtaTransactionManager
JpaTransactionManager
JmsTransactionManager
GrailsHibernateTransactionManager
PlatformTransactionManager
![Page 11: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/11.jpg)
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
![Page 12: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/12.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
• 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
Configure Hibernate
![Page 13: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/13.jpg)
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
![Page 14: Configure Grails using Spring](https://reader035.vdocuments.site/reader035/viewer/2022073116/5568e371d8b42a287a8b4bd7/html5/thumbnails/14.jpg)
PRODUCTS • CONSULTING • APPLICATION MANAGEMENT • IT OPERATIONS • SUPPORT • TRAINING
• 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
Where to go from here?