SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
@alvaro_sanchez@alvaro_sanchez
Ratpack 101
Álvaro Sánchez-Mariscal
Web Architect - odobo
@alvaro_sanchez
About me
● Passionate Software Developer.
○ Former BEA/Sun instructor, Groovy fanboy since 2006.
● Speaker at Codemotion, JavaLand, GeeCON,
Spring IO, GR8Conf, GGX and Greach.
● Author of several Grails plugins.
● Working now at as a Web Architect.
@alvaro_sanchez
About
● HTML5 platform for gambling games.
● We provide game developers a Javascript SDK.
● Server side logic and maths are handled by our
industry certified game engines.
● Seamless integration with several casinos.
● Check out play.odobo.com and play for free!
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Slides, code and workshop available
● Slides:
○ http://www.slideshare.net/alvarosanchezmariscal/
● Companion code:
○ https://github.com/alvarosanchez/ratpack-101-talk
● Workshop:
○ https://github.com/alvarosanchez/ratpack-101
@alvaro_sanchez
Before we start
● Raise your hand if you know:
○ Java.
○ Groovy.
○ Spock.
○ Ratpack?
@alvaro_sanchez
Introduction
● Ratpack is:
○ A set of Java 8 libraries…
○ … lightweight, un-opinionated, Netty-based...
○ … for writing non-blocking HTTP applications…
○ … focused on performance and efficiency…
○ … with an emphasis on testability..
○ … embracing Java 8 or Groovy as programming
languages.
@alvaro_sanchez
When to use Ratpack?
● For microservices.
● For high performance applications.
● For lightweight services (no container,
batteries included).
@alvaro_sanchez
Ratpack is developer friendly
● Startup in milliseconds.
● Development-time reloading with Spring
Loaded.
● First-class support for functional testing.
@alvaro_sanchez
Demo
1. Groovy script.
2. Gradle build with Lazybones.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Handlers
● An incoming request is passed through the
handler chain.
● A handler can:
○ Respond to the request.
○ Delegate to the next handler in the chain.
○ Insert more handlers in the chain and delegate to
them.
@alvaro_sanchez
Handlers
● Each handler is given a Context instance.
○ To interact with the request / response objects.
○ To access the registry.
○ Etc.
● Note that Ratpack is not based on the Servlet
API.
@alvaro_sanchez
Demo
3. Handlers.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
The Context
● The Context provides:
○ Access to the HTTP Request and Response objects.
○ Interaction with other handlers through next() and
insert() methods.
○ Access to objects in the registry.
@alvaro_sanchez
The registry
● The context is also a Registry of objects.
● Handlers can store objects into the context for
use by downstream handlers.
@alvaro_sanchez
Demo
4. Working with the context.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
Ratpack modules
● Ratpack can integrate with Google Guice for:
○ Dependency injection for services, etc.
○ Officially supported modules.
○ Reusing your own components as your modules.
@alvaro_sanchez
Official modules (1/2)
● Benchmarks (JMH).
● Metrics.
● H2 Database.
● Handlebars.
● HikariCP JDBC pool.
● Hystrix.
● Jackson.
● New Relic.
● Pac4J.
● Reactor.
● Groovy Remote
Control.
@alvaro_sanchez
Official modules (2/2)
● RxJava.
● HTTP Sessions.
● Spring Boot.
● Thymeleaf.
@alvaro_sanchez
Demo
5. Using Guice and the Jackson module.
@alvaro_sanchez
Agenda
● Introduction.
● The handlers chain.
● The context.
● Ratpack modules.
● Asynchronous & Non Blocking model.
● Q&A.
@alvaro_sanchez
The classic approach
● A thread-per-request.
○ There is a relatively large thread pool.
○ Each request is assigned a thread from the pool.
○ If the request handling code performs blocking I/O, the
thread sleeps until the result is received.
● Overhead: thread management, memory
consumption.
@alvaro_sanchez
Ratpack’s value proposition
● HTTP IO is event-driven (non blocking).
○ Powered by Netty.
● Handler chain is organised as a pipeline of
asynchronous functions.
○ Small compute thread pool.
○ Blocking operations are executed in a separate pool.
○ Integration with existing libraries like RxJava.
@alvaro_sanchez
Async model
● Ratpack guarantees a deterministic flow.
○ Promises are executed in the order they are defined.
○ Once the promises are resolved, they are executed in
compute threads.
● Async functions can be composed.
○ To avoid the callback hell.
@alvaro_sanchez
Demo
6. Asynchronous model.
@alvaro_sanchez
Álvaro Sánchez-Mariscal
Web Architect - odobo
Images courtesy of
Dzięki!

Mais conteúdo relacionado

Semelhante a Ratpack 101 - GeeCON 2015

Who needs containers in a serverless world
Who needs containers in a serverless worldWho needs containers in a serverless world
Who needs containers in a serverless world
Matthias Luebken
 

Semelhante a Ratpack 101 - GeeCON 2015 (20)

Efficient HTTP applications on the JVM with Ratpack - JDD 2015
Efficient HTTP applications on the JVM with Ratpack - JDD 2015Efficient HTTP applications on the JVM with Ratpack - JDD 2015
Efficient HTTP applications on the JVM with Ratpack - JDD 2015
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016
Efficient HTTP applications on the JVM with Ratpack - Voxxed Days Berlin 2016
 
GraphQL Bangkok meetup 5.0
GraphQL Bangkok meetup 5.0GraphQL Bangkok meetup 5.0
GraphQL Bangkok meetup 5.0
 
Evolve with laravel
Evolve with laravelEvolve with laravel
Evolve with laravel
 
Why Concurrency is hard ?
Why Concurrency is hard ?Why Concurrency is hard ?
Why Concurrency is hard ?
 
Building Fullstack Serverless GraphQL APIs In The Cloud
Building Fullstack Serverless GraphQL APIs In The CloudBuilding Fullstack Serverless GraphQL APIs In The Cloud
Building Fullstack Serverless GraphQL APIs In The Cloud
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
 
Rolando Santamaría Masó - Simplicity meets scalability - code.talks 2015
Rolando Santamaría Masó - Simplicity meets scalability - code.talks 2015Rolando Santamaría Masó - Simplicity meets scalability - code.talks 2015
Rolando Santamaría Masó - Simplicity meets scalability - code.talks 2015
 
AngularJS workshop for beginners.
AngularJS workshop for beginners.AngularJS workshop for beginners.
AngularJS workshop for beginners.
 
Kotlin REST & GraphQL API
Kotlin REST & GraphQL APIKotlin REST & GraphQL API
Kotlin REST & GraphQL API
 
Who needs containers in a serverless world
Who needs containers in a serverless worldWho needs containers in a serverless world
Who needs containers in a serverless world
 
apachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfapachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdf
 
Efficient Django
Efficient DjangoEfficient Django
Efficient Django
 
Ensuring Performance in a Fast-Paced Environment (CMG 2014)
Ensuring Performance in a Fast-Paced Environment (CMG 2014)Ensuring Performance in a Fast-Paced Environment (CMG 2014)
Ensuring Performance in a Fast-Paced Environment (CMG 2014)
 
Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - Copenhagen
 
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
Data Science Salon: A Journey of Deploying a Data Science Engine to ProductionData Science Salon: A Journey of Deploying a Data Science Engine to Production
Data Science Salon: A Journey of Deploying a Data Science Engine to Production
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
 
Netty training
Netty trainingNetty training
Netty training
 

Mais de Alvaro Sanchez-Mariscal

Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Alvaro Sanchez-Mariscal
 

Mais de Alvaro Sanchez-Mariscal (20)

Serverless functions with Micronaut
Serverless functions with MicronautServerless functions with Micronaut
Serverless functions with Micronaut
 
Asynchronous and event-driven Grails applications
Asynchronous and event-driven Grails applicationsAsynchronous and event-driven Grails applications
Asynchronous and event-driven Grails applications
 
6 things you need to know about GORM 6
6 things you need to know about GORM 66 things you need to know about GORM 6
6 things you need to know about GORM 6
 
Reactive microservices with Micronaut - GR8Conf EU 2018
Reactive microservices with Micronaut - GR8Conf EU 2018Reactive microservices with Micronaut - GR8Conf EU 2018
Reactive microservices with Micronaut - GR8Conf EU 2018
 
Reactive microservices with Micronaut - Greach 2018
Reactive microservices with Micronaut - Greach 2018Reactive microservices with Micronaut - Greach 2018
Reactive microservices with Micronaut - Greach 2018
 
Practical Spring Cloud
Practical Spring CloudPractical Spring Cloud
Practical Spring Cloud
 
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...Creating applications with Grails, Angular JS and Spring Security - G3 Summit...
Creating applications with Grails, Angular JS and Spring Security - G3 Summit...
 
Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016Mastering Grails 3 Plugins - G3 Summit 2016
Mastering Grails 3 Plugins - G3 Summit 2016
 
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring Security
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring SecurityDesarrollo de aplicaciones con Grails 3, Angular JS y Spring Security
Desarrollo de aplicaciones con Grails 3, Angular JS y Spring Security
 
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf U...
 
Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016Mastering Grails 3 Plugins - GR8Conf US 2016
Mastering Grails 3 Plugins - GR8Conf US 2016
 
Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016Mastering Grails 3 Plugins - GR8Conf EU 2016
Mastering Grails 3 Plugins - GR8Conf EU 2016
 
Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...
Creating applications with Grails, Angular JS and Spring Security - GR8Conf E...
 
Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016Mastering Grails 3 Plugins - Greach 2016
Mastering Grails 3 Plugins - Greach 2016
 
Creating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring SecurityCreating applications with Grails, Angular JS and Spring Security
Creating applications with Grails, Angular JS and Spring Security
 
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015Stateless authentication with OAuth 2 and JWT - JavaZone 2015
Stateless authentication with OAuth 2 and JWT - JavaZone 2015
 
Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015
 
Stateless authentication for microservices - Spring I/O 2015
Stateless authentication for microservices  - Spring I/O 2015Stateless authentication for microservices  - Spring I/O 2015
Stateless authentication for microservices - Spring I/O 2015
 
Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015
 
Stateless authentication for microservices applications - JavaLand 2015
Stateless authentication for microservices applications -  JavaLand 2015Stateless authentication for microservices applications -  JavaLand 2015
Stateless authentication for microservices applications - JavaLand 2015
 

Último

Último (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

Ratpack 101 - GeeCON 2015