SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Lari Hotari @lhotari
Pivotal Software, Inc.
Ratpack and
Grails 3
Agenda
• Grails 3 and Ratpack
• Why async?
• Modularity and micro service architectures
• Embrace Gradle
• Abstract packaging / deployment
• Reach outside the servlet container
• App profiles: Netty, Servlet, Batch, Hadoop
• Lightweight deployments, support micro
services
Grails 3
Why Netty / Ratpack?
Why async?
Amdahl's law
Programming model
• Declarative programming expresses the logic of
a computation without describing its control flow.
• It's programming without the call stack, the
programmer doesn't decide execution details.
• Examples: functional and reactive
programming, event / message based
execution, distributed parallel computation
algorithms like Map/Reduce
15 import ratpack.rx.RxRatpack
16 import ratpack.session.SessionModule
17 import ratpack.session.store.MapSessionsModule
18 import ratpack.session.store.SessionStorage
19
20 import static ratpack.groovy.Groovy.groovyTemplate
21 import static ratpack.groovy.Groovy.ratpack
22 import static ratpack.jackson.Jackson.json
23 import static ratpack.pac4j.internal.SessionConstants.USER_PROFILE
24
25 ratpack {
26 bindings {
27 bind DatabaseHealthCheck
28 add new CodaHaleMetricsModule().jvmMetrics().jmx().websocket().
29 healthChecks()
30 add new HikariModule([URL: "jdbc:h2:mem:dev;INIT=CREATE SCHEMA IF NOT
31 EXISTS DEV"], "org.h2.jdbcx.JdbcDataSource")
32 add new SqlModule()
33 add new JacksonModule()
34 add new BookModule()
35 add new RemoteControlModule()
36 add new SessionModule()
37 add new MapSessionsModule(10, 5)
38 add new Pac4jModule<>(new FormClient("/login", new
39 SimpleTestUsernamePasswordAuthenticator()), new
40 AuthPathAuthorizer())
41
42 init { BookService bookService ->
43 RxRatpack.initialize()
44 HystrixRatpack.initialize()
45 bookService.createTable()
46 }
47 }
48
49 handlers { BookService bookService ->
50
51 get {
52 bookService.all().toList().subscribe { List<Book> books ->
53 SessionStorage sessionStorage = request.get(SessionStorage)
54 UserProfile profile = sessionStorage.get(USER_PROFILE)
55 def username = profile?.getAttribute("username")
56
57 render groovyTemplate("listing.html",
58 username: username ?: "",
59 title: "Books",
60 books: books,
61 msg: request.queryParams.msg ?: "")
62 }
63 }
64
65 handler("create") {
66 byMethod {
67 get {
68 render groovyTemplate("create.html", title: "Create Book")
69 }
70 post {
71 Form form = parse(Form)
72 bookService.insert(
73 form.isbn,
74 form.get("quantity").asType(Long),
75 form.get("price").asType(BigDecimal)
76 ).single().subscribe { String isbn ->
77 redirect "/?msg=Book+$isbn+created"
78 }
79 }
80 }
81 }
82
83 handler("update/:isbn") {
84 def isbn = pathTokens["isbn"]
85
86 bookService.find(isbn).single().subscribe { Book book ->
87 if (book == null) {
88 clientError(404)
89 } else {
90 byMethod {
91 get {
92 render groovyTemplate("update.html", title:
93 "Update Book", book: book)
94 }
95 post {
96 Form form = parse(Form)
97 bookService.update(
98 isbn,
99 form.get("quantity").asType(Long),
100 form.get("price").asType(BigDecimal)
101 ) subscribe {
102 redirect "/?msg=Book+$isbn+updated"
103 }
104 }
105 }
106 }
107 }
108 }
109
110 post("delete/:isbn") {
111 def isbn = pathTokens["isbn"]
112 bookService.delete(isbn).subscribe {
113 redirect "/?msg=Book+$isbn+deleted"
114 }
115 }
116
117 prefix("api") {
118 get("books") {
119 bookService.all().toList().subscribe { List<Book> books ->
120 render json(books)
121 }
122 }
123
124 handler("book/:isbn?", registry.get(BookRestEndpoint))
81 }
82
83 handler("update/:isbn") {
84 def isbn = pathTokens["isbn"]
85
86 bookService.find(isbn).single().subscribe { Book book ->
87 if (book == null) {
88 clientError(404)
89 } else {
90 byMethod {
91 get {
92 render groovyTemplate("update.html", title:
93 "Update Book", book: book)
94 }
95 post {
96 Form form = parse(Form)
97 bookService.update(
98 isbn,
99 form.get("quantity").asType(Long),
100 form.get("price").asType(BigDecimal)
101 ) subscribe {
102 redirect "/?msg=Book+$isbn+updated"
103 }
104 }
105 }
106 }
107 }
108 }
109
110 post("delete/:isbn") {
111 def isbn = pathTokens["isbn"]
112 bookService.delete(isbn).subscribe {
113 redirect "/?msg=Book+$isbn+deleted"
source: https://github.com/ratpack/example-books/blob/master/src/ratpack/Ratpack.groovy
Ratpack application
consists of
functional handler
chains
Ratpack applications
• Ratpacks comes with Guice for dependency injection
• Guice modules are also used as the plugin system for
Ratpack
• Examples of Ratpack module contributions:
• Integrations to RxJava and Reactor. Can be used for
async composition and preventing "callback hell".
• Integration to Netflix Hystrix for adding error resilience
functionality . f.e., Circuit-breaker pattern impl.
Demo
Ratpack and Grails (GORM) used together
• https://github.com/lhotari/ratpack-gorm-example
• Spring Boot embedded in Ratpack, running
GORM
Modularity
• logical partitioning of the "software design"
• allows complex software to be manageable for
the purpose of implementation and maintenance
Coupling and Cohesion
• Coupling and cohesion are measures for
describing how easy it will be to change the
behaviour of some element in a system
• Modules are coupled if a change in one forces a
change in a the other
• A module's cohesion is a measure of whether it's
responsibilities form a meaningful unit
source: GOOS book
• Low coupling between modules ⟹ easier to
change
• High cohesion within module ⟹ single
responsibility
Microservice definition
by James Lewis
• Each application only does one thing
• Small enough to fit in your head
• Small enough that you can throw them away
• Embedded web container
• Packaged as a single executable jar
• Use HTTP and HATEOAS to decouple services
• Each app exposes metrics about itself
–Arnon Rotem-Gal-Oz, Practical SOA
“Nanoservice is an Anti-pattern where a
service is too fine grained. Nanoservice is a
service whose overhead (communications,
maintenance etc.) out-weights its utility.”
Polygot persistence
• Common principle is that each service owns it's data -
there is no shared database across multiple services.
• If this principle is followed, it usually means switching
to Hexagonal architecture, where persistence is an
integration and not part of the core.
• "Start with the events and behaviour instead of the
database."
• Data consistency models in distributed systems
Brooks: "No silver bullet"
• Essential complexity
• complexity that you cannot escape
• Accidental complexity
• we could be adding complexity by bad design
- Google's "Solve for X"
“You don't spend your time
being bothered that you can't
teleport from here to Japan,
because there's a part of you
that thinks it's impossible. !
Moonshot thinking is choosing
to be bothered by that.”
Modular monoliths
• Modular monoliths are composed of loosely coupled
modules of single responsibility
• Enabling the 3rd way (after monoliths and
microservices) for building applications on the JVM
across different libraries and frameworks
• Modules can be turned into true micro services when
needed - instead of introducing accidental complexity
to projects that don't really require micro services in
the beginning, but could benefit of them later
The monoliths in the micro
services architecture
Single Page
App in
Browser
API Gateway
service
µservice
A
SAAS Service
A
SAAS Service
B
µservice
B
µservice
C
µservice
D
µservice
E
µservice
F
"If you built it..."
 pretotyping.org
“Make sure you are building the
right it before you build it right."
!
"Fail fast ... and Often"
Lari Hotari @lhotari
Pivotal Software, Inc.
Thank you!

Mais conteúdo relacionado

Mais procurados

The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your data
Christian Posta
 
Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...
Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...
Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...
Majid Hajibaba
 

Mais procurados (9)

Welcome To CloudLand! Intro to the Cloud Native Landscape
Welcome To CloudLand! Intro to the Cloud Native LandscapeWelcome To CloudLand! Intro to the Cloud Native Landscape
Welcome To CloudLand! Intro to the Cloud Native Landscape
 
The 6 Rules for Modernizing Your Legacy Java Monolith with Microservices
The 6 Rules for Modernizing Your Legacy Java Monolith with MicroservicesThe 6 Rules for Modernizing Your Legacy Java Monolith with Microservices
The 6 Rules for Modernizing Your Legacy Java Monolith with Microservices
 
Designing a Service Mesh with Kafka and Sagas | David Navalho, Marionete and ...
Designing a Service Mesh with Kafka and Sagas | David Navalho, Marionete and ...Designing a Service Mesh with Kafka and Sagas | David Navalho, Marionete and ...
Designing a Service Mesh with Kafka and Sagas | David Navalho, Marionete and ...
 
Cloud Computing Principles and Paradigms: 7 enhancing cloud computing environ...
Cloud Computing Principles and Paradigms: 7 enhancing cloud computing environ...Cloud Computing Principles and Paradigms: 7 enhancing cloud computing environ...
Cloud Computing Principles and Paradigms: 7 enhancing cloud computing environ...
 
The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your data
 
Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...
Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...
Cloud Computing Principles and Paradigms: 6 on the management of virtual mach...
 
QCon NYC: Distributed systems in practice, in theory
QCon NYC: Distributed systems in practice, in theoryQCon NYC: Distributed systems in practice, in theory
QCon NYC: Distributed systems in practice, in theory
 
[WSO2Con USA 2018] Deploying Applications in K8S and Docker
[WSO2Con USA 2018] Deploying Applications in K8S and Docker[WSO2Con USA 2018] Deploying Applications in K8S and Docker
[WSO2Con USA 2018] Deploying Applications in K8S and Docker
 
Clocker Now and Next
Clocker Now and NextClocker Now and Next
Clocker Now and Next
 

Destaque (6)

Forex AutoPilot
Forex AutoPilotForex AutoPilot
Forex AutoPilot
 
Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web Framework
 
High Performance Microservices with Ratpack and Spring Boot
High Performance Microservices with Ratpack and Spring BootHigh Performance Microservices with Ratpack and Spring Boot
High Performance Microservices with Ratpack and Spring Boot
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms Ingesting Drone Data into Big Data Platforms
Ingesting Drone Data into Big Data Platforms
 
CSS Grid Layout
CSS Grid LayoutCSS Grid Layout
CSS Grid Layout
 

Semelhante a Ratpack and Grails 3

BISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple SpacesBISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple Spaces
Srinath Perera
 

Semelhante a Ratpack and Grails 3 (20)

Microservice message routing on Kubernetes
Microservice message routing on KubernetesMicroservice message routing on Kubernetes
Microservice message routing on Kubernetes
 
Exploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservicesExploring Twitter's Finagle technology stack for microservices
Exploring Twitter's Finagle technology stack for microservices
 
AngularJS
AngularJSAngularJS
AngularJS
 
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland KuhnReactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2Microservices with Apache Camel, Docker and Fabric8 v2
Microservices with Apache Camel, Docker and Fabric8 v2
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensions
 
Lagom : Reactive microservice framework
Lagom : Reactive microservice frameworkLagom : Reactive microservice framework
Lagom : Reactive microservice framework
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
 
Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
 
Jclouds Intro
Jclouds IntroJclouds Intro
Jclouds Intro
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
BISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple SpacesBISSA: Empowering Web gadget Communication with Tuple Spaces
BISSA: Empowering Web gadget Communication with Tuple Spaces
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
SpringPeople - Introduction to Cloud Computing
SpringPeople - Introduction to Cloud ComputingSpringPeople - Introduction to Cloud Computing
SpringPeople - Introduction to Cloud Computing
 
Managing your camels in the cloud with CI/CD
Managing your camels in the cloud with CI/CDManaging your camels in the cloud with CI/CD
Managing your camels in the cloud with CI/CD
 
'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...'How to build efficient backend based on microservice architecture' by Anton ...
'How to build efficient backend based on microservice architecture' by Anton ...
 
Software Development: Beyond Training wheels
Software Development: Beyond Training wheelsSoftware Development: Beyond Training wheels
Software Development: Beyond Training wheels
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 

Último

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Último (20)

%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 

Ratpack and Grails 3

  • 1. Lari Hotari @lhotari Pivotal Software, Inc. Ratpack and Grails 3
  • 2. Agenda • Grails 3 and Ratpack • Why async? • Modularity and micro service architectures
  • 3. • Embrace Gradle • Abstract packaging / deployment • Reach outside the servlet container • App profiles: Netty, Servlet, Batch, Hadoop • Lightweight deployments, support micro services Grails 3
  • 4.
  • 5. Why Netty / Ratpack? Why async?
  • 7. Programming model • Declarative programming expresses the logic of a computation without describing its control flow. • It's programming without the call stack, the programmer doesn't decide execution details. • Examples: functional and reactive programming, event / message based execution, distributed parallel computation algorithms like Map/Reduce
  • 8. 15 import ratpack.rx.RxRatpack 16 import ratpack.session.SessionModule 17 import ratpack.session.store.MapSessionsModule 18 import ratpack.session.store.SessionStorage 19 20 import static ratpack.groovy.Groovy.groovyTemplate 21 import static ratpack.groovy.Groovy.ratpack 22 import static ratpack.jackson.Jackson.json 23 import static ratpack.pac4j.internal.SessionConstants.USER_PROFILE 24 25 ratpack { 26 bindings { 27 bind DatabaseHealthCheck 28 add new CodaHaleMetricsModule().jvmMetrics().jmx().websocket(). 29 healthChecks() 30 add new HikariModule([URL: "jdbc:h2:mem:dev;INIT=CREATE SCHEMA IF NOT 31 EXISTS DEV"], "org.h2.jdbcx.JdbcDataSource") 32 add new SqlModule() 33 add new JacksonModule() 34 add new BookModule() 35 add new RemoteControlModule() 36 add new SessionModule() 37 add new MapSessionsModule(10, 5) 38 add new Pac4jModule<>(new FormClient("/login", new 39 SimpleTestUsernamePasswordAuthenticator()), new 40 AuthPathAuthorizer()) 41 42 init { BookService bookService -> 43 RxRatpack.initialize() 44 HystrixRatpack.initialize() 45 bookService.createTable() 46 } 47 } 48 49 handlers { BookService bookService -> 50 51 get { 52 bookService.all().toList().subscribe { List<Book> books -> 53 SessionStorage sessionStorage = request.get(SessionStorage) 54 UserProfile profile = sessionStorage.get(USER_PROFILE) 55 def username = profile?.getAttribute("username") 56 57 render groovyTemplate("listing.html", 58 username: username ?: "", 59 title: "Books", 60 books: books, 61 msg: request.queryParams.msg ?: "") 62 } 63 } 64 65 handler("create") { 66 byMethod { 67 get { 68 render groovyTemplate("create.html", title: "Create Book") 69 } 70 post { 71 Form form = parse(Form) 72 bookService.insert( 73 form.isbn, 74 form.get("quantity").asType(Long), 75 form.get("price").asType(BigDecimal) 76 ).single().subscribe { String isbn -> 77 redirect "/?msg=Book+$isbn+created" 78 } 79 } 80 } 81 } 82 83 handler("update/:isbn") { 84 def isbn = pathTokens["isbn"] 85 86 bookService.find(isbn).single().subscribe { Book book -> 87 if (book == null) { 88 clientError(404) 89 } else { 90 byMethod { 91 get { 92 render groovyTemplate("update.html", title: 93 "Update Book", book: book) 94 } 95 post { 96 Form form = parse(Form) 97 bookService.update( 98 isbn, 99 form.get("quantity").asType(Long), 100 form.get("price").asType(BigDecimal) 101 ) subscribe { 102 redirect "/?msg=Book+$isbn+updated" 103 } 104 } 105 } 106 } 107 } 108 } 109 110 post("delete/:isbn") { 111 def isbn = pathTokens["isbn"] 112 bookService.delete(isbn).subscribe { 113 redirect "/?msg=Book+$isbn+deleted" 114 } 115 } 116 117 prefix("api") { 118 get("books") { 119 bookService.all().toList().subscribe { List<Book> books -> 120 render json(books) 121 } 122 } 123 124 handler("book/:isbn?", registry.get(BookRestEndpoint)) 81 } 82 83 handler("update/:isbn") { 84 def isbn = pathTokens["isbn"] 85 86 bookService.find(isbn).single().subscribe { Book book -> 87 if (book == null) { 88 clientError(404) 89 } else { 90 byMethod { 91 get { 92 render groovyTemplate("update.html", title: 93 "Update Book", book: book) 94 } 95 post { 96 Form form = parse(Form) 97 bookService.update( 98 isbn, 99 form.get("quantity").asType(Long), 100 form.get("price").asType(BigDecimal) 101 ) subscribe { 102 redirect "/?msg=Book+$isbn+updated" 103 } 104 } 105 } 106 } 107 } 108 } 109 110 post("delete/:isbn") { 111 def isbn = pathTokens["isbn"] 112 bookService.delete(isbn).subscribe { 113 redirect "/?msg=Book+$isbn+deleted" source: https://github.com/ratpack/example-books/blob/master/src/ratpack/Ratpack.groovy Ratpack application consists of functional handler chains
  • 9. Ratpack applications • Ratpacks comes with Guice for dependency injection • Guice modules are also used as the plugin system for Ratpack • Examples of Ratpack module contributions: • Integrations to RxJava and Reactor. Can be used for async composition and preventing "callback hell". • Integration to Netflix Hystrix for adding error resilience functionality . f.e., Circuit-breaker pattern impl.
  • 10. Demo Ratpack and Grails (GORM) used together • https://github.com/lhotari/ratpack-gorm-example • Spring Boot embedded in Ratpack, running GORM
  • 11.
  • 12. Modularity • logical partitioning of the "software design" • allows complex software to be manageable for the purpose of implementation and maintenance
  • 13. Coupling and Cohesion • Coupling and cohesion are measures for describing how easy it will be to change the behaviour of some element in a system • Modules are coupled if a change in one forces a change in a the other • A module's cohesion is a measure of whether it's responsibilities form a meaningful unit source: GOOS book
  • 14. • Low coupling between modules ⟹ easier to change • High cohesion within module ⟹ single responsibility
  • 15. Microservice definition by James Lewis • Each application only does one thing • Small enough to fit in your head • Small enough that you can throw them away • Embedded web container • Packaged as a single executable jar • Use HTTP and HATEOAS to decouple services • Each app exposes metrics about itself
  • 16. –Arnon Rotem-Gal-Oz, Practical SOA “Nanoservice is an Anti-pattern where a service is too fine grained. Nanoservice is a service whose overhead (communications, maintenance etc.) out-weights its utility.”
  • 17. Polygot persistence • Common principle is that each service owns it's data - there is no shared database across multiple services. • If this principle is followed, it usually means switching to Hexagonal architecture, where persistence is an integration and not part of the core. • "Start with the events and behaviour instead of the database." • Data consistency models in distributed systems
  • 18. Brooks: "No silver bullet" • Essential complexity • complexity that you cannot escape • Accidental complexity • we could be adding complexity by bad design
  • 19. - Google's "Solve for X" “You don't spend your time being bothered that you can't teleport from here to Japan, because there's a part of you that thinks it's impossible. ! Moonshot thinking is choosing to be bothered by that.”
  • 20. Modular monoliths • Modular monoliths are composed of loosely coupled modules of single responsibility • Enabling the 3rd way (after monoliths and microservices) for building applications on the JVM across different libraries and frameworks • Modules can be turned into true micro services when needed - instead of introducing accidental complexity to projects that don't really require micro services in the beginning, but could benefit of them later
  • 21. The monoliths in the micro services architecture Single Page App in Browser API Gateway service µservice A SAAS Service A SAAS Service B µservice B µservice C µservice D µservice E µservice F
  • 22. "If you built it..."
  • 23.  pretotyping.org “Make sure you are building the right it before you build it right." ! "Fail fast ... and Often"
  • 24. Lari Hotari @lhotari Pivotal Software, Inc. Thank you!