GGX 2014 - Grails and the real time world
-
Upload
ivan-lopez -
Category
Technology
-
view
520 -
download
1
Transcript of GGX 2014 - Grails and the real time world
![Page 1: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/1.jpg)
GRAILS AND THE REAL-TIME WORLD
Iván López @ilopmar
![Page 2: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/2.jpg)
Hello!I am Iván López
@ilopmar
http://greachconf.com@madridgug
![Page 3: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/3.jpg)
Traditional architectures
Request-response
POST /register-user
POST /register-user
POST /register-user
![Page 4: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/4.jpg)
Traditional architectures
![Page 5: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/5.jpg)
Traditional architectures
![Page 6: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/6.jpg)
“A problem postponed is a problem solved.
Really?
![Page 7: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/7.jpg)
1.Event Driven Architectures
![Page 8: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/8.jpg)
Event Driven Architecture
▷ Fire & Forget
▷ Decouple producer and consumer
▷ Immediate action in the consumer
▷ Real-time
![Page 9: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/9.jpg)
Traditional architecture
POST /purchase
POST /purchase - Receive request 5 ms - Data validation 20 ms - Save 40 ms - PDF generation 200 ms - Send email 80 ms - Render response 50 ms
Total: 395 ms
![Page 10: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/10.jpg)
“Can we do it better?
![Page 11: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/11.jpg)
Event driven architecture
POST /purchase
POST /purchase - Receive request 5 ms No - Data validation 20 ms No - Save 40 ms No - PDF generation 200 ms Yes - Send email 80 ms Yes - Render response 50 ms No
Total: 115 ms ~ 70% better
Can anyone else do it?
Total: 115 ms ~ 70% better
![Page 12: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/12.jpg)
Event driven architecture
POST /purchase
PDFGeneration
POST /purchase - Receive request 5 ms - Data validation 20 ms - Save 40 ms - Render response 50 ms
Total: 115 msSend email
![Page 13: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/13.jpg)
“Don't keep your clients waiting unnecessarily!
Can I defer it?
![Page 14: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/14.jpg)
Goals
▷ Loosely coupled architecture, easy to extend and evolve
▷ Build high performance and scalable systems
▷ Keep the business logic where “it belongs”
![Page 15: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/15.jpg)
What about Grails?
▷ Platform core
▷ Events plugin
▷ Executor plugin
▷ Grails 2.3 async
![Page 16: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/16.jpg)
Synchronous example
// Send confirmation emaildef user = new User(params).save()emailService.sendRegistationMail(user)render view:'registerOk'
class EmailService { public void sendRegistrationMail(User user) { sendMail { to user.email subject "Confirm your account" html g.render(template: "userEmailConfirmation") } }}
![Page 17: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/17.jpg)
Asynchronous example
// Platform coredef user = new User(params).save()event('sendRegistrationMail', user)render view:'registerOk'
class EmailService { @grails.events.Listener public void sendRegistrationMail(User user) { sendMail { to user.email subject "Confirm your account" html g.render(template: "userEmailConfirmation") } }}
![Page 18: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/18.jpg)
Asynchronous example
// Executordef user = new User(params).save()runAsync { emailService.sendRegistationMail(user)}render view:'registerOk'
class EmailService { public void sendRegistrationMail(User user) { sendMail { to user.email subject "Confirm your account" html g.render(template: "userEmailConfirmation") } }}
![Page 19: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/19.jpg)
“I love the smell of code in the morning
![Page 20: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/20.jpg)
What if we don't want this?
▷ Extract “dependencies” to configuration
▷ Change the application behaviour modifying the configuration
![Page 21: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/21.jpg)
Spring Integration
Use inside Spring thewell-knownEnterprise IntegrationPatterns
http://www.enterpriseintegrationpatterns.com/
![Page 22: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/22.jpg)
Spring Integration
▷ Lightweight messaging mechanism for Spring applications
▷ High level abstraction for messaging
▷ Application code is not aware of the messaging API
▷ External systems integration declaring adapters
![Page 23: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/23.jpg)
Message
▷ Payload
▷ Header
▷ Immutable
![Page 24: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/24.jpg)
Channel
▷ Point-to-point
▷ Publish-Subscribe
![Page 25: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/25.jpg)
Endpoints
▷ Transformer
▷ Filter
▷ Router
▷ Splitter
▷ Aggregator
▷ Service activator
▷ Channel-adapter
▷ Enricher
▷ Bridge
▷ ...
![Page 26: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/26.jpg)
Adapters
▷ JMS▷ AMQP▷ TCP▷ UDP▷ File▷ FTP▷ RMI▷ HTTP (Rest)▷ WS
▷ Mail▷ JDBC▷ XMPP▷ Twitter▷ RSS▷ MongoDB▷ Redis
▷ Gemfire▷ Stream
![Page 27: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/27.jpg)
“Talk is cheap. Show me the code.
![Page 28: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/28.jpg)
2.Demo
![Page 29: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/29.jpg)
3.Summary
![Page 30: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/30.jpg)
Summary
▷ Grails standard architecture fits in most of the cases
▷ It doesn't scale to infinite (and beyond!)
▷ Think about the application you're building
▷ Think about information flow
![Page 31: GGX 2014 - Grails and the real time world](https://reader033.fdocuments.us/reader033/viewer/2022052912/55a20a391a28aba0368b4645/html5/thumbnails/31.jpg)
Thanks!Any questions?
@ilopmar
https://github.com/lmivan
Iván López
http://kcy.me/1dwf7