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.
SpringBoot to Quarkus
migration
Contents
1. who am i
2. what can you expect
3. what is quarkus
4. why migrate
5. migration
a. application description
b. s...
$ whoami
JUG leader in the BarcelonaJUG
Organiser at JBCNConf ( Barcelona )
Software Engineer at Red Hat
App. Modernisatio...
What can you expect ?
My experience
v 2.1.5
v 1.2.0
opinionated option
magistral lecture
something that works
THE way
Quarkus brief description
What is Quarkus ?
A Kubernetes Native, Java, Scala, Kotlin stack
tailored for GraalVM and OpenJDK HotSpot
crafted from the...
300x faster 10x smaller focused on easy to code
opensource fast paced releases tons of extensions
Quarkus key facts
Quarkus extensions ( > 90 )
Kafka
Camel
Keycloak
Spring
Vert.x
RestEasy
….
Microprofile
Openshift
Jaegger
Flyway
Hibernate...
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 !...
Quarkus performance
Quarkus OSS status
Migration of
Spring PetClinic REST
Why to migrate
My experience
with an easy CDI, REST, …
long startup times, eternal tests,
applications super big,
easy to ...
Application migrated
Spring Data ( repositories, jdbc , ... )
Spring Web ( REST )
Spring Security
Spring documentation ( S...
Elements not migrated
Spring JDBC querying
* no helper methods to work with Inserts, Updates….
* no equivalent to org.spri...
CDI
● Replace Autowired by Inject
● Beans declaration using @ApplicationScoped
● Auto injection on Constructors
● Lazy by ...
CDI
PROs
● straight forward migration for Beans
● no feature missing
CONs
● no annotation built-in beans
injection dependi...
JPA Repositories
● Repository classes to implement PanacheRepositoryBase<T, Integer>
Quarkus will generate the implementat...
JPA Repositories
PROs
● straightforward migration
CONs
● no Query DSL methods
Application
● Removed SpringApplication class
Quarkus doesn’t need a main entry application class
( needed to configure Op...
Spring REST to JAX-RS
● Move from Spring REST to the standard JAX-RS
@RestController
@RequestMapping, @GetMapping,
@PostMa...
Spring REST to JAX-RS
PROs
● straightforward migration
INFO
● Spring also supports JAX-RS as 3rd party lib
Spring REST Security to Quarkus Security
● replaced Spring REST Security
Spring REST JDBC Security to Elytron JDBC realm
Add extension dependency : elytron-security-jdbc
Configure on properties f...
Spring REST Security to Quarkus security
PROs
● Almost the same result
● By configuration rather than code
CONs
● Quarkus ...
CORS
● configured CORS in the application.properties file
CORS
PROs
● easy to enable , no code involved
CONs
● at global level, not per Controller
Metrics
● Add smallRye metrics extension
● Annotate each method ( for custom metrics )
Metrics
PROs
● OpenMetrics standard naming
CONs
● different naming than micrometer
( compatibility toggle being developed ...
Validation
● Spring Validation to Hibernate Validator
● Move from @ControllerAdvice to JAX-RS ExceptionMapper
Swagger ( OpenAPI v 3.0 )
● Add extension “openapi”
● Add RestApplication
Validation
PROs
● standard
● easy
CONs
● Spring has more MVC features
Swagger ( OpenAPI v 3.0 )
PROs
● straightforward migration
● standard and easy way to configure
● Swagger-UI OOTB
CONs
● n...
AOP for app metrics
● use of microprofile metrics annotations
AOP for repository metrics
● using Hibernate built in metrics enabled in properties
AOP for app metrics
PROs
● standard
● easy to customise
CONs
● need to annotate ALL methods one by one for
custom app metr...
Local caching
● Spring uses a default ConcurrentHashMap
● Caffeine uses a ConcurrentLinkedHashMap
● Add “cache” extension ...
Local Caching
PROs
● easy to implement and configure
● straightforward migration
CONs
● none
Test : REST
MockMVC -> RestAssured
Test REST
PROs
● RESTassured is easy to handle and very intuitive
CONs
● No way to simulate Roles without creating an user...
Test : Mocking
Create a Java class extending your real class and put it in Test folder
Tbh, I haven’t done it… I prefer to...
Test - resources
● Annotate test suites with @QuarkusTest to boot the app
● Annotate test suites with @QuarkusTestResource...
BUT……
Spring API compatible with Quarkus
Spring WEB ( REST) : spring-web extension
Using same Spring API for REST Supported Annotations
@RestController
@RequestMap...
Spring DI : spring-di extension
Using same API as Spring DI
Annotations Supported
@Autowired @Repository
@Qualifier @Scope...
Spring Data : spring-data-jpa
Using same API for Spring Data Supported
Any interface of : Repository,
CrudRepository, Pagi...
Spring Security: spring-security extension
Using same API as Spring Security
Annotations Supported
@Secured
@Preauthorized...
Performance comparative ( not exhaustive )
SPRING QUARKUS
JVM
QUARKUS
GraalVM
build
( uber-jar )
4 s
43 Mb
13 s
43 Mb
133 ...
Summary
● Using specialised standard and open libraries
● Easy to code
● Full of documentation and examples
● Quarkus team...
References
Repositories
● Spring REST PetClinic
https://github.com/spring-petclinic/spring-petclinic-rest
● Quarkus REST P...
Interactive Tutorials ( Katacoda )
● https://developers.redhat.com/courses/quarkus/
List of Tutorials
● Getting Started
● ...
Cheat Sheet
● https://lordofthejars.github.io/quarkus-cheat-sheet/
by Alex Soto
Do you want to start coding with Quarkus ?
https://code.quarkus.io/
Windup
● Opensource tool to help on applications migrations
○ https://github.com/windup
○ to cloud readyness
○ to EAP...
○...
Thank you for having the patience to attend
and also to all who have
directly or indirectly helped me on this talk.
Specia...
Upcoming SlideShare
Loading in …5
×

Migration Spring Boot PetClinic REST to Quarkus 1.2.0

In this presentation I will introduce Quarkus and also show which were the steps followed to migrate Spring PetClinic application to Quarkus using the standard libraries : resteasy, microprofile metrics, hibernate, openapi, .... GraalVM

  • Be the first to comment

Migration Spring Boot PetClinic REST to Quarkus 1.2.0

  1. 1. SpringBoot to Quarkus migration
  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. summary 8. references
  3. 3. $ whoami JUG leader in the BarcelonaJUG Organiser at JBCNConf ( Barcelona ) Software Engineer at Red Hat App. Modernisation and Migration team Learning to play guitar Learning Frozen songs to sing with my daughter. @vilojona jvilalop@redhat.com aytartana.wordpress.com github.com/jonathanvila
  4. 4. What can you expect ? My experience v 2.1.5 v 1.2.0 opinionated option magistral lecture something that works THE way
  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 of Spring PetClinic REST
  13. 13. Why to migrate My experience with an easy CDI, REST, … long startup times, eternal tests, applications super big, easy to develope applications feeling of “lots of things happen under the hood” easy to develop applications, fast lightweight not everything ready
  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 )
  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. Application ● Removed SpringApplication class Quarkus doesn’t need a main entry application class ( needed to configure OpenApi )
  21. 21. 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
  22. 22. Spring REST to JAX-RS PROs ● straightforward migration INFO ● Spring also supports JAX-RS as 3rd party lib
  23. 23. Spring REST Security to Quarkus Security ● replaced Spring REST Security
  24. 24. Spring REST JDBC Security to Elytron JDBC realm Add extension dependency : elytron-security-jdbc Configure on properties file and remove configureGlobal method
  25. 25. Spring REST Security to Quarkus security PROs ● Almost the same result ● By configuration rather than code CONs ● Quarkus doesn’t have an expression language
  26. 26. CORS ● configured CORS in the application.properties file
  27. 27. CORS PROs ● easy to enable , no code involved CONs ● at global level, not per Controller
  28. 28. Metrics ● Add smallRye metrics extension ● Annotate each method ( for custom metrics )
  29. 29. 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
  30. 30. Validation ● Spring Validation to Hibernate Validator ● Move from @ControllerAdvice to JAX-RS ExceptionMapper
  31. 31. Swagger ( OpenAPI v 3.0 ) ● Add extension “openapi” ● Add RestApplication
  32. 32. Validation PROs ● standard ● easy CONs ● Spring has more MVC features
  33. 33. Swagger ( OpenAPI v 3.0 ) PROs ● straightforward migration ● standard and easy way to configure ● Swagger-UI OOTB CONs ● not REST paths scan configuration
  34. 34. AOP for app metrics ● use of microprofile metrics annotations
  35. 35. AOP for repository metrics ● using Hibernate built in metrics enabled in properties
  36. 36. 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
  37. 37. Local caching ● Spring uses a default ConcurrentHashMap ● Caffeine uses a ConcurrentLinkedHashMap ● Add “cache” extension ( Caffeine ) and annotate the method
  38. 38. Local Caching PROs ● easy to implement and configure ● straightforward migration CONs ● none
  39. 39. Test : REST MockMVC -> RestAssured
  40. 40. 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
  41. 41. Test : Mocking Create a Java class extending your real class and put it in Test folder Tbh, I haven’t done it… I prefer to use Mockito
  42. 42. Test - resources ● Annotate test suites with @QuarkusTest to boot the app ● Annotate test suites with @QuarkusTestResource to load an embedded resource
  43. 43. BUT…… Spring API compatible with Quarkus
  44. 44. 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
  45. 45. 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
  46. 46. 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
  47. 47. Spring Security: spring-security extension Using same API as Spring Security Annotations Supported @Secured @Preauthorized Expressions allowed hasAnyRole permitAll denyAll isAnonymous isAuthenticated #paramName ==
  48. 48. Performance comparative ( not exhaustive ) SPRING QUARKUS JVM QUARKUS GraalVM build ( uber-jar ) 4 s 43 Mb 13 s 43 Mb 133 s 85 Mb boot 7.985 s 634.2 Mb 2.7 s 287.3 Mb 0.431 s 15.9 Mb
  49. 49. Summary ● Using specialised standard and open libraries ● Easy to code ● Full of documentation and examples ● Quarkus team/community is awesome ● Fast release cadence ● Few bugs on extensions ( but they fix them like Speedy Gonzalez ) ● No-reflection goal can have some limitations ( AOP … ) ● Not everything has a 1:1 migration ( Query DSL Methods , … )
  50. 50. References 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
  51. 51. 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
  52. 52. Cheat Sheet ● https://lordofthejars.github.io/quarkus-cheat-sheet/ by Alex Soto
  53. 53. Do you want to start coding with Quarkus ? https://code.quarkus.io/
  54. 54. Windup ● Opensource tool to help on applications migrations ○ https://github.com/windup ○ to cloud readyness ○ to EAP... ○ soon to Quarkus
  55. 55. Thank you for having the patience to attend and also to all who have directly or indirectly helped me on this talk. Special thanks to : David Gómez, Alejandro Martinez, Abel Salgado Alex Soto, Georgios Andrianakis and the rest of Red Hat Quarkus team @vilojona jvilalop@redhat.com aytartana.wordpress.com github.com/jonathanvila

×