Successfully reported this slideshow.
Your SlideShare is downloading. ×

Ratpack: the core for your microservices for jdk.io 2016

Ratpack: the core for your microservices for jdk.io 2016

Download to read offline

Ratpack reached version 1.0 in 2015. It's a light-weight framework with a lot of potential. It has a good team and years for coding behind it, but still remains very straight-forward, easy to use, deploy, extend and at the same time it's very efficient and performing. Its core is non-blocking and implements reactive approaches for handling high-load with little resources. It has all you need for your micro-services.

Ratpack reached version 1.0 in 2015. It's a light-weight framework with a lot of potential. It has a good team and years for coding behind it, but still remains very straight-forward, easy to use, deploy, extend and at the same time it's very efficient and performing. Its core is non-blocking and implements reactive approaches for handling high-load with little resources. It has all you need for your micro-services.

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Ratpack: the core for your microservices for jdk.io 2016

  1. 1. 01
  2. 2. About me 02
  3. 3. Andrey Adamovich Java/Groovy developer DevOps guy, automation junkie Co­author of Groovy 2 Cookbook Co­organizer of @latcraft and @devternity • • • • 03
  4. 4. Contact details E­mail: andrey@aestasit.com Linkedin: http://www.linkedin.com/in/andreyadamovich Lanyrd: http://lanyrd.com/profile/andrey­adamovich GitHub: https://github.com/aadamovich SO: http://stackoverflow.com/users/162792/andrey­adamovich Twitter: @codingandrey, @aestasit • • • • • • 04
  5. 5. Let's start! 05
  6. 6. Microservices In 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
  7. 7. Quick Start! 07
  8. 8. 0. Prerequisites Install Java 8+ Install Groovy 2.4+ (Optionally) install Gradle 2+ (or just use Gradle Wrapper) • • • 08
  9. 9. 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
  10. 10. 1. Continue... ratpack {   handlers {     get {       response.send "Time on jdk.io is " +           new Date().toString()      }   } } 01. 02. 03. 04. 05. 06. 07. 08. 10
  11. 11. 2. Save as... ratpack.groovy01. 11
  12. 12. 3. Start! groovy ratpack.groovy 01. 12
  13. 13. 4. Enable some more logging JAVA_OPTS=‐Dgroovy.grape.report.downloads=true01. 13
  14. 14. Ratpack facts 14
  15. 15. Ratpack facts Ratpack is a toolset that combines several Java libraries that allows efficiently developing performant and testable HTTP applications. 15
  16. 16. Ratpack facts Inspired by Sinatra framework Requires Java 8 Does not require a EE container Does not implement Servlet API Goes under Apache 2.0 License • • • • • 16
  17. 17. Ratpack facts Core 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) Out­of­the­box integration with Guice and Spring • • • • 17
  18. 18. Stack 18
  19. 19. It's alive and very active! 19
  20. 20. Release history 0.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
  21. 21. Release history 0.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
  22. 22. Release history 0.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
  23. 23. Release history 1.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
  24. 24. Commit history 24
  25. 25. Statistics 25
  26. 26. Team 26
  27. 27. Top contributor 27
  28. 28. Modules I Common: config, session Reactive: rx, remote Authentication: pac4j Build/Packaging: gradle Database: h2, hikari • • • • • 28
  29. 29. Modules II Dependency Injection: guice, spring­boot JSON: jackson Language support: groovy, kotlin Reliability: hystrix, dropwizard­metrics, newrelic Templates: handlebars, thymeleaf, groovy Testing: test, groovy­test • • • • • • 29
  30. 30. Java + Groovy = ? Has similar performance to Java when using  invokeDynamic Supports static compilation and compile­time type checking Useful for defining rich DSLs with type checking via  Closure parameters and  @DelegatesTo  annotations • • • 30
  31. 31. IDE support IntelliJ IDEA recommended Eclipse has poor support for Groovy, @DelegatesTo and functional interfaces NetBeans ­ haven't even tried • • • 31
  32. 32. Diving deeper 32
  33. 33. Handlers All 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
  34. 34. A handler can Send 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
  35. 35. Flow 35
  36. 36. Let's write some code! 36
  37. 37. Demo: Date server 37
  38. 38. Paths and parameters prefix('api') {   get('user/:id') {     render getUser(pathTokens.id)   }   get('friends') {     render getFriendList()   } } 01. 02. 03. 04. 05. 06. 07. 08. 38
  39. 39. Verbs path('user') {   byMethod {     get { ... }     post { ... }     put { ... }     delete { ... }   } } 01. 02. 03. 04. 05. 06. 07. 08. 39
  40. 40. Content types path('user') {   byContent {     json { ... }     xml { ... }     type("application/vnd.app.org+json;v=1") {       ...     }   } } 01. 02. 03. 04. 05. 06. 07. 08. 09. 40
  41. 41. Static content files {    dir "public"    file "index.html" } 01. 02. 03. 04. 41
  42. 42. Templates (ala JSP/GSP) Handler code: get ("admin") {   render groovyTemplate('admin.html', result: "") } 01. 02. 03. 42
  43. 43. Templates (ala JSP/GSP) admin.html : <% if (model?.result) { %>   <% model.result.each { %>     <li>${it}</li>   <% } %> <% } %> 01. 02. 03. 04. 05. 43
  44. 44. Templates (Groovy­way) Handler code: render groovyMarkupTemplate(   "update.gtpl",    "title: "Update Book",   ...   "price": book.price ) 01. 02. 03. 04. 05. 06. 44
  45. 45. Templates (Groovy­way) 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
  46. 46. Testing Test handler implementations with  RequestFixture Functional testing with  ApplicationUnderTest  and TestHttpClient Nobody canceled testing with Geb (Selenium)! • • • 46
  47. 47. Demo: Geb Test 47
  48. 48. Let's build services! 48
  49. 49. Service setup 49
  50. 50. Quick start lazybones create ratpack <project> gradlew idea gradlew run ‐‐continuous • • • 50
  51. 51. Demo: Lazybones + IDEA51
  52. 52. Demo: Services 52
  53. 53. Operational aspects Can't even make WAR! Very peaceful! Publish JAR/TAR/ZIP in to artifact repository Or use os­package plugin to create DEB/RPM package Integrate with provisioning/configuration management tools Consider monitoring/metrics • • • • • 53
  54. 54. Puppet: defined type define service::booking(   $deployment_port,   $deployment_host,   $enabled                = true,   $development_mode       = false,   $revision               = latest, ) {   ... } 01. 02. 03. 04. 05. 06. 07. 08. 09. 54
  55. 55. Puppet: fetch file { "/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
  56. 56. Puppet: auto­build exec { "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
  57. 57. Puppet: service file { "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
  58. 58. Puppet: service service { "booking_${name}":   ensure   => $enabled ?      { true => "running",        default => "stopped" },   enable   => $enabled,   provider => upstart, } 01. 02. 03. 04. 05. 06. 07. 58
  59. 59. Combining options Chef/Ansible Etcd/Consul/Eureka Docker • • • 59
  60. 60. Monitoring Hystrix Dropwizard Metrics • • 60
  61. 61. What's next? 61
  62. 62. Going further 62
  63. 63. Demo: Examples Books63
  64. 64. Summary 64
  65. 65. Take­aways Ratpack 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 non­blocking 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
  66. 66. Reading material http://ratpack.io http://www.slideshare.net/search/slideshow?q=ratpack https://github.com/ratpack http://alvarosanchez.github.io/ratpack­101/ • • • • 66
  67. 67. Book 67
  68. 68. Contribute! 68
  69. 69. Questions? 69
  70. 70. Thank you! 70
  71. 71. Devternity 1­2 of December, 2016, Riga Software Excellence Conference 4 tracks, 30+ speakers, 6 workshops http://devternity.com • • • • 71

×