ratpack: the core for your microservices for jdk.io 2016
TRANSCRIPT
![Page 1: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/1.jpg)
01
![Page 2: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/2.jpg)
About me02
![Page 3: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/3.jpg)
Andrey AdamovichJava/Groovy developer
DevOps guy, automation junkie
Coauthor of Groovy 2 Cookbook
Coorganizer of @latcraft and @devternity
••••
03
![Page 4: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/4.jpg)
Contact detailsEmail: [email protected]
Linkedin: http://www.linkedin.com/in/andreyadamovich
Lanyrd: http://lanyrd.com/profile/andreyadamovich
GitHub: https://github.com/aadamovich
SO: http://stackoverflow.com/users/162792/andreyadamovich
Twitter: @codingandrey, @aestasit
••••••
04
![Page 5: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/5.jpg)
Let's start!05
![Page 6: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/6.jpg)
MicroservicesIn short, the microservice architectural style is an approach to
developing a single application as a suite of small services, each
running in its own process and communicating with lightweight
mechanisms, often an HTTP resource API.
James Lewis & Martin Fowler
“06
![Page 7: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/7.jpg)
Quick Start!07
![Page 8: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/8.jpg)
0. PrerequisitesInstall Java 8+
Install Groovy 2.4+
(Optionally) install Gradle 2+ (or just use Gradle Wrapper)
•••
08
![Page 9: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/9.jpg)
1. Type in...@Grab("io.ratpack:ratpack‐groovy:1.4.1")
@Grab('org.slf4j:slf4j‐simple:1.7.21')
import static ratpack.groovy.Groovy.ratpack
01.
02.
03.
09
![Page 10: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/10.jpg)
1. Continue...ratpack {
handlers {
get {
response.send "Time on jdk.io is " +
new Date().toString()
}
}
}
01.
02.
03.
04.
05.
06.
07.
08.
10
![Page 11: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/11.jpg)
2. Save as...ratpack.groovy01.
11
![Page 12: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/12.jpg)
3. Start!groovy ratpack.groovy 01.
12
![Page 13: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/13.jpg)
4. Enable some more loggingJAVA_OPTS=‐Dgroovy.grape.report.downloads=true01.
13
![Page 14: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/14.jpg)
Ratpack facts
14
![Page 15: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/15.jpg)
Ratpack factsRatpack is a toolset that combines several Java libraries that allows
efficiently developing performant and testable HTTP applications.
15
![Page 16: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/16.jpg)
Ratpack factsInspired by Sinatra framework
Requires Java 8
Does not require a EE container
Does not implement Servlet API
Goes under Apache 2.0 License
•••••
16
![Page 17: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/17.jpg)
Ratpack factsCore is very minimal and is only based on few abstractions (Handler,
Registry, Service)
Many additional modules exist and it's easily to develop new ones
Modules are injected through DI (there is no specialized plugin
system)
Outofthebox integration with Guice and Spring
•
••
•
17
![Page 18: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/18.jpg)
Stack
18
![Page 19: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/19.jpg)
It's alive andvery active!19
![Page 20: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/20.jpg)
Release history0.5.2 Jul 21, 2012
0.6.1 Nov 29, 2012
0.9.0 Jan 02, 2014
0.9.1 Feb 01, 2014
0.9.2 Mar 01, 2014
0.9.3 Apr 01, 2014
0.9.4 May 01, 2014
0.9.5 Jun 01, 2014
0.9.6 Jul 01, 2014
••••••••• 20
![Page 21: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/21.jpg)
Release history0.9.7 Aug 01, 2014
0.9.8 Sep 01, 2014
0.9.9 Oct 01, 2014
0.9.10 Nov 02, 2014
0.9.11 Dec 01, 2014
0.9.12 Jan 01, 2014
0.9.13 Feb 01, 2015
0.9.14 Mar 01, 2015
••••••••
21
![Page 22: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/22.jpg)
Release history0.9.15 Apr 01, 2015
0.9.16 May 02, 2015
0.9.17 June 02, 2015
0.9.18 July 02, 2015
0.9.19 Aug 02, 2015
1.0.0 Sep 15, 2015
1.1.1 Oct 21, 2015
1.2.0 Feb 17, 2016
••••••••
22
![Page 23: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/23.jpg)
Release history1.3.0 Apr 20, 2016
1.3.1 Apr 23, 2016
1.3.2 Apr 27, 2016
1.3.3 Apr 28, 2016
1.4.0 Aug 09, 2016
1.4.1 Aug 23, 2016
••••••
23
![Page 24: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/24.jpg)
Commit history
24
![Page 25: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/25.jpg)
Statistics
25
![Page 26: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/26.jpg)
Team
26
![Page 27: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/27.jpg)
Top contributor
27
![Page 28: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/28.jpg)
Modules ICommon: config, session
Reactive: rx, remote
Authentication: pac4j
Build/Packaging: gradle
Database: h2, hikari
•••••
28
![Page 29: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/29.jpg)
Modules IIDependency Injection: guice, springboot
JSON: jackson
Language support: groovy, kotlin
Reliability: hystrix, dropwizardmetrics, newrelic
Templates: handlebars, thymeleaf, groovy
Testing: test, groovytest
••••••
29
![Page 30: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/30.jpg)
Java + Groovy = ?Has similar performance to Java when using invokeDynamic
Supports static compilation and compiletime type checking
Useful for defining rich DSLs with type checking via Closure
parameters and @DelegatesTo annotations
•••
30
![Page 31: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/31.jpg)
IDE supportIntelliJ IDEA recommended
Eclipse has poor support for Groovy, @DelegatesTo and functional
interfaces
NetBeans haven't even tried
••
•
31
![Page 32: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/32.jpg)
Diving deeper32
![Page 33: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/33.jpg)
HandlersAll request processing is done via composition of Handler s.
Each Handler in the Chain is asked to respond to a Request until
one actually does.
••
33
![Page 34: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/34.jpg)
A handler canSend a Response based on the Request .
Delegate to the next Handler in the Chain .
Insert Handler s into the Chain and immediately delegate to them.
Change Context , which represents the current state of the
Request processing.
••••
34
![Page 35: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/35.jpg)
Flow
35
![Page 36: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/36.jpg)
Let's writesome code!36
![Page 37: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/37.jpg)
Demo: Dateserver
37
![Page 38: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/38.jpg)
Paths and parametersprefix('api') {
get('user/:id') {
render getUser(pathTokens.id)
}
get('friends') {
render getFriendList()
}
}
01.
02.
03.
04.
05.
06.
07.
08.
38
![Page 39: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/39.jpg)
Verbspath('user') {
byMethod {
get { ... }
post { ... }
put { ... }
delete { ... }
}
}
01.
02.
03.
04.
05.
06.
07.
08.
39
![Page 40: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/40.jpg)
Content typespath('user') {
byContent {
json { ... }
xml { ... }
type("application/vnd.app.org+json;v=1") {
...
}
}
}
01.
02.
03.
04.
05.
06.
07.
08.
09. 40
![Page 41: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/41.jpg)
Static contentfiles {
dir "public"
file "index.html"
}
01.
02.
03.
04.
41
![Page 42: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/42.jpg)
Templates (ala JSP/GSP)Handler code:
get ("admin") {
render groovyTemplate('admin.html', result: "")
}
01.
02.
03.
42
![Page 43: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/43.jpg)
Templates (ala JSP/GSP)admin.html :
<% if (model?.result) { %>
<% model.result.each { %>
<li>${it}</li>
<% } %>
<% } %>
01.
02.
03.
04.
05.
43
![Page 44: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/44.jpg)
Templates (Groovyway)Handler code:
render groovyMarkupTemplate(
"update.gtpl",
"title: "Update Book",
...
"price": book.price
)
01.
02.
03.
04.
05.
06.
44
![Page 45: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/45.jpg)
Templates (Groovyway)update.gtpl :
layout 'layout.gtpl',
title: title,
msg: msg,
bodyContents: contents {
h1('Update Book')
includeGroovy '_book_form.gtpl'
}
01.
02.
03.
04.
05.
06.
07.
45
![Page 46: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/46.jpg)
TestingTest handler implementations with RequestFixture
Functional testing with ApplicationUnderTest and
TestHttpClient
Nobody canceled testing with Geb (Selenium)!
••
•
46
![Page 47: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/47.jpg)
Demo: GebTest
47
![Page 48: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/48.jpg)
Let's buildservices!
48
![Page 49: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/49.jpg)
Service setup
49
![Page 50: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/50.jpg)
Quick startlazybones create ratpack <project>
gradlew idea
gradlew run ‐‐continuous
•••
50
![Page 51: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/51.jpg)
Demo:Lazybones +
IDEA51
![Page 52: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/52.jpg)
Demo:Services
52
![Page 53: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/53.jpg)
Operational aspectsCan't even make WAR! Very peaceful!
Publish JAR/TAR/ZIP in to artifact repository
Or use ospackage plugin to create DEB/RPM package
Integrate with provisioning/configuration management tools
Consider monitoring/metrics
•••••
53
![Page 54: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/54.jpg)
Puppet: defined typedefine service::booking(
$deployment_port,
$deployment_host,
$enabled = true,
$development_mode = false,
$revision = latest,
) {
...
}
01.
02.
03.
04.
05.
06.
07.
08.
09. 54
![Page 55: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/55.jpg)
Puppet: fetchfile { "/services/booking/environments/${name}":
ensure => directory
}
vcsrepo { "/services/booking/environments/${name}":
ensure => $revision,
provider => git,
source => 'https://github.com/jdk.io/booking.git',
notify => Exec["build booking ${name} api"]
}
01.
02.
03.
04.
05.
06.
07.
08.
09. 55
![Page 56: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/56.jpg)
Puppet: autobuildexec { "build garagetravel ${name} api":
cwd => "/services/booking/environments/${name}",
refreshonly => true,
command =>
"/services/booking/../${name}/gradlew installApp",
notify => Service["booking_${name}"]
}
01.
02.
03.
04.
05.
06.
07.
56
![Page 57: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/57.jpg)
Puppet: servicefile { "booking ${name} service":
path => "/etc/init/booking_${name}.conf",
content => template('booking/service.conf.erb'),
notify => Service["booking_${name}"]
}
01.
02.
03.
04.
05.
57
![Page 58: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/58.jpg)
Puppet: serviceservice { "booking_${name}":
ensure => $enabled ?
{ true => "running",
default => "stopped" },
enable => $enabled,
provider => upstart,
}
01.
02.
03.
04.
05.
06.
07.
58
![Page 59: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/59.jpg)
Combining optionsChef/Ansible
Etcd/Consul/Eureka
Docker
•••
59
![Page 60: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/60.jpg)
MonitoringHystrix
Dropwizard Metrics••
60
![Page 61: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/61.jpg)
What's next?
61
![Page 62: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/62.jpg)
Going further
62
![Page 63: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/63.jpg)
Demo:ExamplesBooks
63
![Page 64: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/64.jpg)
Summary64
![Page 65: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/65.jpg)
TakeawaysRatpack can be used to quickly prototype web APIs and applications.
Learning curve is really small, you can start in seconds.
It can be used to create high performance web applications due to
nonblocking architecture.
Ratpack does not lock you in the way you implement data access,
session handling, logging, etc.
Ratpack has vibrant community and actively evolving code base.
•••
•
•
65
![Page 66: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/66.jpg)
Reading materialhttp://ratpack.io
http://www.slideshare.net/search/slideshow?q=ratpack
https://github.com/ratpack
http://alvarosanchez.github.io/ratpack101/
••••
66
![Page 67: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/67.jpg)
Book
67
![Page 68: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/68.jpg)
Contribute!68
![Page 69: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/69.jpg)
Questions?69
![Page 70: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/70.jpg)
Thank you!70
![Page 71: Ratpack: the core for your microservices for jdk.io 2016](https://reader036.vdocument.in/reader036/viewer/2022081604/5883ece61a28ab34428b54f3/html5/thumbnails/71.jpg)
Devternity12 of December, 2016, Riga
Software Excellence Conference
4 tracks, 30+ speakers, 6 workshops
http://devternity.com
••••
71