geecon krakow 2015 - grails and the real-time world

33
GeeCON 2015 Grails and the real-time world IVÁN LÓPEZ - @ilopmar

Upload: ivan-lopez

Post on 21-Jul-2015

237 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: GeeCON Krakow 2015 - Grails and the real-time world

GeeCON 2015

Grails and thereal-time world

IVÁN LÓPEZ - @ilopmar

Page 2: GeeCON Krakow 2015 - Grails and the real-time world

Hello!I am Iván López

@ilopmar

http://greachconf.com@madridgug

Page 3: GeeCON Krakow 2015 - Grails and the real-time world

Traditional architectures

Request-response

POST /register-user

POST /register-user

POST /register-user

Page 4: GeeCON Krakow 2015 - Grails and the real-time world

Traditional architectures

Page 5: GeeCON Krakow 2015 - Grails and the real-time world

Traditional architectures

Page 6: GeeCON Krakow 2015 - Grails and the real-time world

“A problem postponed is a problem solved.

Really?

Page 7: GeeCON Krakow 2015 - Grails and the real-time world

1.Event Driven Architectures

Page 8: GeeCON Krakow 2015 - Grails and the real-time world

Event Drive Architectures

▷ Fire & Forget

▷ Decouple producer and consumer

▷ Immediate action in the consumer

▷ Real-time

Page 9: GeeCON Krakow 2015 - Grails and the real-time world

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: GeeCON Krakow 2015 - Grails and the real-time world

“Can we do it better?

Page 11: GeeCON Krakow 2015 - Grails and the real-time world

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?

Page 12: GeeCON Krakow 2015 - Grails and the real-time world

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: GeeCON Krakow 2015 - Grails and the real-time world

“Don't keep your clients waiting unnecessarily!

Can I defer it?

Page 14: GeeCON Krakow 2015 - Grails and the real-time world

Goals

▷ Loosely coupled architecture, easy to extend and evolve.

▷ Build high performance and scalable systems

▷ Keep the business logic where “it belongs”

Page 15: GeeCON Krakow 2015 - Grails and the real-time world

What about Grails?

▷ Platform core plugin

▷ Events plugin

▷ Executor plugin

▷ Grails 2.3+ async

Page 16: GeeCON Krakow 2015 - Grails and the real-time world

Synchronous example

// Send confirmation emaildef user = new User(params).save()emailService.sendRegistrationMail(user)render view:'registerOk'

Page 17: GeeCON Krakow 2015 - Grails and the real-time world

Synchronous example

// Send confirmation emaildef user = new User(params).save()emailService.sendRegistrationMail(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 18: GeeCON Krakow 2015 - Grails and the real-time world

Asynchronous example

// Platform coredef user = new User(params).save()event 'sendRegistrationMail', userrender view:'registerOk'

Page 19: GeeCON Krakow 2015 - Grails and the real-time world

Asynchronous example

// Platform coredef user = new User(params).save()event 'sendRegistrationMail', userrender 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 20: GeeCON Krakow 2015 - Grails and the real-time world

Asynchronous example

// Executordef user = new User(params).save()runAsync { emailService.sendRegistrationMail(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 21: GeeCON Krakow 2015 - Grails and the real-time world

“I love the smell of code in the morning

Page 22: GeeCON Krakow 2015 - Grails and the real-time world

What if we don't want this?

▷ Extract “dependencies” to configuration

▷ Change application behaviour modifying the configuration

Page 23: GeeCON Krakow 2015 - Grails and the real-time world

Spring Integration

Use inside Spring the well-know Enterprise Integration Patterns

http://www.enterpriseintegrationpatterns.com/

Page 24: GeeCON Krakow 2015 - Grails and the real-time world

Spring Integration

▷ Lightweight messaging mechanism for Spring apps

▷ High level abstraction for messaging

▷ External systems integration declaring adapters

Page 25: GeeCON Krakow 2015 - Grails and the real-time world

Message

▷ Payload

▷ Headers

▷ Immutable

Page 26: GeeCON Krakow 2015 - Grails and the real-time world

Channels

▷ Point-to-point

▷ Publish-Subscribe

Page 27: GeeCON Krakow 2015 - Grails and the real-time world

Endpoints

▷ Transformer

▷ Filter

▷ Router

▷ Splitter

▷ Aggregator

▷ Service activator

▷ Channel-adapter

▷ Enricher

▷ Bridge

▷ ...

Page 28: GeeCON Krakow 2015 - Grails and the real-time world

Adapters

▷ JMS

▷ AMQP

▷ TCP

▷ UDP

▷ File

▷ FTP

▷ RMI

▷ HTTP (Rest)

▷ WS

▷ Mail

▷ JDBC

▷ XMPP

▷ Twitter

▷ RSS

▷ MongoDB

▷ Redis

▷ Gemfire

▷ Stream

Page 29: GeeCON Krakow 2015 - Grails and the real-time world

“Talk is cheap. Show me the code.

Page 30: GeeCON Krakow 2015 - Grails and the real-time world

2.Demo

Page 31: GeeCON Krakow 2015 - Grails and the real-time world

3.Summary

Page 32: GeeCON Krakow 2015 - Grails and the real-time world

Summary

▷ Grails standard architecture fits in most of the cases

▷ It does not scale to infinite (and beyond!)

▷ Think about the application you are building

▷ Keep the information flow in mind

Page 33: GeeCON Krakow 2015 - Grails and the real-time world

Thanks!Any questions?

@ilopmar

[email protected]

https://github.com/lmivan

Iván López

http://kcy.me/22ze3