Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk

Running a Spring Boot application but still want to benefit from Quarkus and its supersonic, subatomic Java capabilities? Me too! With a “hello world” everything looks simple, but what about a real app? Will it be easy? Or fun? In this session we’ll show our experience migrating a Spring Boot app to Quarkus. Technologies involved in the app include Hibernate, Prometheus, REST endpoints, and more. Be prepared to listen to a journey of reality, failure, and wins in the Quarkus universe.

Related Books

Free with a 30 day trial from Scribd

See all
  • Be the first to comment

Spring Boot to Quarkus: A real app migration experience | DevNation Tech Talk

  1. 1. Migrating QUARKUS
  2. 2. Contents 1. who am i 2. what can you expect 3. what is quarkus 4. why migrate 5. migration a. application description b. steps 6. performance comparative 7. references
  3. 3. $ whoami JUG organiser at BarcelonaJUG Cofounder of JBCNConf ( Barcelona ) Software Engineer at Red Hat App. Modernisation and Migration team @vilojona jvilalop@redhat.com aytartana.wordpress.com github.com/jonathanvila
  4. 4. What can you expect ? My experience v 2.2.5 v 1.7.0 opinionated option magistral lecture something that works THE way QUARKUS
  5. 5. Quarkus brief description
  6. 6. What is Quarkus ? A Kubernetes Native, Java, Scala, Kotlin stack tailored for GraalVM and OpenJDK HotSpot crafted from the best of breed Java libraries and standards.
  7. 7. 300x faster 10x smaller focused on easy to code opensource fast paced releases tons of extensions Quarkus key facts
  8. 8. Quarkus extensions ( > 90 ) Kafka Camel Keycloak Spring Vert.x RestEasy …. Microprofile Openshift Jaegger Flyway Hibernate Infinispan ...
  9. 9. Quarkus evolution 2018-12 v 0.0.1 2019-06 v 0.15.0 2019-11 v 1.0.0 Release 2020-01 v 1.2.0 1 minor version every 2 weeks !!! (+/-)
  10. 10. Quarkus performance
  11. 11. Quarkus OSS status
  12. 12. Migration
  13. 13. Why to migrate My experience easy to develop with an easy CDI, REST, … long startup times, eternal tests heavyweight too many things happen under the hood easy to develop applications fast lightweight GraalVM compatible QUARKUS ✅ FaaS compatible ( lambdas ) ✅ less money on public cloud
  14. 14. Application migrated Spring Data ( repositories, jdbc , ... ) Spring Web ( REST ) Spring Security Spring documentation ( Swagger ) Spring actuators Spring micrometer Spring CDI Spring AOP Spring cache Hibernate Panache JaxRS Quarkus Security OpenAPI SmallRye Health Microprofile Metrics CDI Spec ( Arc ) --- Quarkus cache ( Caffeine ) QUARKUS
  15. 15. Elements not migrated Spring JDBC querying * no helper methods to work with Inserts, Updates…. * no equivalent to org.springframework.jdbc.core classes * we need to reimplement everything using AGROAL JMX * not supported by GraalVM definition
  16. 16. CDI ● Replace Autowired by Inject ● Beans declaration using @ApplicationScoped ● Auto injection on Constructors ● Lazy by default
  17. 17. CDI PROs ● straight forward migration for Beans ● no feature missing CONs ● no annotation built-in beans injection depending on Profile ● no private members on injection
  18. 18. JPA Repositories ● Repository classes to implement PanacheRepositoryBase<T, Integer> Quarkus will generate the implementation of the usual methods : list , find, persist, delete
  19. 19. JPA Repositories PROs ● straightforward migration CONs ● no Query DSL methods
  20. 20. Spring REST to JAX-RS ● Move from Spring REST to the standard JAX-RS @RestController @RequestMapping, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping @PathVariable @Path @GET, @POST, @PUT @DELETE @PathParam QUARKUS
  21. 21. Spring REST to JAX-RS PROs ● straightforward migration INFO ● Spring also supports JAX-RS as 3rd party lib
  22. 22. Spring REST Security to Quarkus Security ● replaced Spring REST Security
  23. 23. Spring REST JDBC Security to Elytron JDBC realm Add extension dependency : elytron-security-jdbc Configure on properties file and remove configureGlobal method
  24. 24. Spring REST Security to Quarkus security PROs ● Almost the same result ● By configuration rather than code CONs ● Quarkus doesn’t have an expression language
  25. 25. CORS ● configured CORS in the application.properties file
  26. 26. CORS PROs ● easy to enable , no code involved CONs ● at global level, not per Controller
  27. 27. Metrics ● Add smallRye metrics extension ● Annotate each method ( for custom metrics )
  28. 28. Metrics PROs ● OpenMetrics standard naming CONs ● different naming than micrometer ( compatibility toggle being developed ) ● not the same metrics ● no AOP so you need to annotate every method
  29. 29. Validation ● Spring Validation to Hibernate Validator ● Move from @ControllerAdvice to JAX-RS ExceptionMapper
  30. 30. Validation PROs ● standard ● easy CONs ● none
  31. 31. Swagger ( OpenAPI v 3.0 ) ● Add extension “openapi” ● extend Application
  32. 32. Swagger ( OpenAPI v 3.0 ) PROs ● straightforward migration ● standard and easy way to configure ● Swagger-UI OOTB CONs ● not REST paths scan configuration
  33. 33. AOP for app metrics ● use of microprofile metrics annotations
  34. 34. AOP for repository metrics ● using Hibernate built in metrics enabled in properties
  35. 35. AOP for app metrics PROs ● standard ● easy to customise CONs ● need to annotate ALL methods one by one for custom app metrics ● no expression language to define methods affected
  36. 36. Local caching ● Spring uses a default ConcurrentHashMap ● Caffeine uses a ConcurrentLinkedHashMap ● Add “cache” extension ( Caffeine ) and annotate the method
  37. 37. Local Caching PROs ● easy to implement and configure ● straightforward migration CONs ● none
  38. 38. Test : REST MockMVC -> RestAssured
  39. 39. Test REST PROs ● RESTassured is easy to handle and very intuitive CONs ● No way to simulate Roles without creating an user for each role to test INFO ● Changed JSonPath to GPath
  40. 40. Test - resources ● Annotate test suites with @QuarkusTest to boot the app ● Annotate test suites with @QuarkusTestResource to load an embedded resource
  41. 41. Test - Mock ● Use the quarkus-mockito dependency : quarkus-junit5-mockito ● Annotate mocks with @InjectMock
  42. 42. Spring API in Quarkus
  43. 43. Spring WEB ( REST) : spring-web extension Using same Spring API for REST Supported Annotations @RestController @RequestMapping @GetMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping @RequestParam @RequestHeader @MatrixVariable @PathVariable @CookieValue @RequestBody @ResponseStatus @ExceptionHandler
  44. 44. Spring DI : spring-di extension Using same API as Spring DI Annotations Supported @Autowired @Repository @Qualifier @Scope @Value @Component * doesn’t support an expression language @Configuration @Service @Bean
  45. 45. Spring Data : spring-data-jpa Using same API for Spring Data Supported Any interface of : Repository, CrudRepository, PagingAndSortingRepository, JpaRepository Derived Query Methods User defined Queries Not Supported Invocations to any method of QueryByExampleExecutor QueryDSL
  46. 46. Spring Security: spring-security extension Using same API as Spring Security Annotations Supported @Secured @Preauthorized Expressions allowed hasAnyRole permitAll denyAll isAnonymous isAuthenticated #paramName ==
  47. 47. Performance comparative (shallow) SPRING BOOT 2.2.5 QUARKUS Hotspot 1.8 QUARKUS GraalVM 20.1 build ( uber-jar ) 4.3 s 48 Mb 13 s 42 Mb 185 s 97 Mb boot 6.8 s 630 Mb 2.6 s ( 3x ) 251 Mb ( 2.5x ) 0.462 s ( 15x ) 21 Mb ( 30x )
  48. 48. References
  49. 49. Repositories ● Spring REST PetClinic https://github.com/spring-petclinic/spring-petclinic-rest ● Quarkus REST PetClinic https://github.com/jonathanvila/spring-petclinic-rest/tree/quarkus Documentation/News/Help ● https://quarkus.io ● @QuarkusIO ● https://developers.redhat.com/search/?t=quarkus ● quarkus-dev@googlegroups.com
  50. 50. Interactive Tutorials ( Katacoda ) ● https://developers.redhat.com/courses/quarkus/ List of Tutorials ● Getting Started ● For Spring Devs ● Streaming with Kafka ● Hibernate and Panache ● Prometeus & Grafana
  51. 51. Cheat Sheet ● https://lordofthejars.github.io/quarkus-cheat-sheet/ by Alex Soto
  52. 52. Do you want to start coding with Quarkus ? https://code.quarkus.io/
  53. 53. ● Rules to help to migrate from SB to Quarkus ( MTA 5.0 ) ○ Opensource tool to help on applications migrations ■ https://developers.redhat.com/products/mta/overview ■ https://github.com/windup ○ 26 rules , covering ■ DI ■ Integration ■ Metrics ■ JPA ■ Security ■ Web ■ Shell ■ …. Red Hat MTA (Migration Toolkit for Applications)
  54. 54. ● Rules to help to migrate from SB to Quarkus ( MTA 5.0 ) ○ Opensource tool to help on applications migrations ■ https://developers.redhat.com/products/mta/overview ■ https://github.com/windup ○ 26 rules , covering ■ DI ■ Integration ■ Metrics ■ JPA ■ Security ■ Web ■ Shell ■ …. Red Hat MTA (Migration Toolkit for Applications)
  55. 55. ● Rules to help to migrate from SB to Quarkus ( MTA 5.0 ) ○ Opensource tool to help on applications migrations ■ https://developers.redhat.com/products/mta/overview ■ https://github.com/windup ○ 26 rules , covering ■ DI ■ Integration ■ Metrics ■ JPA ■ Security ■ Web ■ Shell ■ …. Red Hat MTA (Migration Toolkit for Applications)
  56. 56. ● Rules to help to migrate from SB to Quarkus ( MTA 5.0 ) ○ Opensource tool to help on applications migrations ■ https://developers.redhat.com/products/mta/overview ■ https://github.com/windup ○ 26 rules , covering ■ DI ■ Integration ■ Metrics ■ JPA ■ Security ■ Web ■ Shell ■ …. ○ Plugin for Eclipse (Che), VSCode Red Hat MTA (Migration Toolkit for Applications)
  57. 57. ● Rules to help to migrate from SB to Quarkus ( MTA 5.0 ) ○ Opensource tool to help on applications migrations ■ https://developers.redhat.com/products/mta/overview ■ https://github.com/windup ○ 26 rules , covering ■ DI ■ Integration ■ Metrics ■ JPA ■ Security ■ Web ■ Shell ■ …. Red Hat MTA (Migration Toolkit for Applications)
  58. 58. ● Rules to help to migrate from SB to Quarkus ( MTA 5.0 ) ○ Opensource tool to help on applications migrations ■ https://developers.redhat.com/products/mta/overview ■ https://github.com/windup ○ 26 rules , covering ■ DI ■ Integration ■ Metrics ■ JPA ■ Security ■ Web ■ Shell ■ …. ○ Plugin for Eclipse (Che), VSCode Red Hat MTA (Migration Toolkit for Applications)
  59. 59. Real use cases Lufthansa Technik AVIATAR experiences significant cloud resources savings by moving to Kubernetes-native Quarkus (link) Suomen Asiakastieto Oy chooses Quarkus for their microservices development (link) Vodafone Greece replaces Spring Boot with Quarkus (link) ● “Quarkus offers by default (without trying to optimize it) is 50%-60% more lightweight (in JVM mode) that what Spring offers” ● “30 to 40% better developer productivity vis-a-vis Spring Boot,” Public Clouds exp. -- Internal Labs --- Save up to : ● 37 % on Cloud ( Quarkus JVM ) ● 71 % on Cloud ( Quarkus + GraalVM )
  60. 60. Books ( devs not only consume tech ) Sci FyMindNovel
  61. 61. @vilojona jvilalop@redhat.com aytartana.wordpress.com github.com/jonathanvila Thank you :)

×