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
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. $ 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. What can you expect ?
My experience
v 2.1.5
v 1.2.0
opinionated option
magistral lecture
something that works
THE way
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. 300x faster 10x smaller focused on easy to code
opensource fast paced releases tons of extensions
Quarkus key facts
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. 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. 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. CDI
● Replace Autowired by Inject
● Beans declaration using @ApplicationScoped
● Auto injection on Constructors
● Lazy by default
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. JPA Repositories
● Repository classes to implement PanacheRepositoryBase<T, Integer>
Quarkus will generate the implementation of the usual methods :
list , find, persist, delete
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. Spring REST to JAX-RS
PROs
● straightforward migration
INFO
● Spring also supports JAX-RS as 3rd party lib
24. Spring REST JDBC Security to Elytron JDBC realm
Add extension dependency : elytron-security-jdbc
Configure on properties file and remove configureGlobal method
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
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
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. AOP for app metrics
● use of microprofile metrics annotations
35. AOP for repository metrics
● using Hibernate built in metrics enabled in properties
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. Local caching
● Spring uses a default ConcurrentHashMap
● Caffeine uses a ConcurrentLinkedHashMap
● Add “cache” extension ( Caffeine ) and annotate the method
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. 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. Test - resources
● Annotate test suites with @QuarkusTest to boot the app
● Annotate test suites with @QuarkusTestResource to load an embedded
resource
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. 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. 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. Spring Security: spring-security extension
Using same API as Spring Security
Annotations Supported
@Secured
@Preauthorized
Expressions allowed
hasAnyRole
permitAll
denyAll
isAnonymous
isAuthenticated
#paramName ==
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. 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 , … )
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
53. Do you want to start coding with Quarkus ?
https://code.quarkus.io/
54. Windup
● Opensource tool to help on applications migrations
○ https://github.com/windup
○ to cloud readyness
○ to EAP...
○ soon to Quarkus
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