SlideShare a Scribd company logo
1 of 34
Download to read 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!

More Related Content

Similar to 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
 

Similar to 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
 

More from 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
 

More from 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
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
"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 ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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 - 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...
 

Ratpack 101 - GeeCON 2015