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.

Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020

"Use Spring Boot! No, use Micronaut!! Nooooo, Quarkus is the best!!!"

There's a lot of developers praising the hottest, and fastest, Java REST frameworks: Micronaut, Quarkus, and Spring Boot. In this session, you'll learn how to do the following with each framework:

✅ Build a REST API
✅ Secure your API with OAuth 2.0
✅ Optimize for production with Docker and GraalVM

I'll also share some performance numbers and pretty graphs to compare community metrics.

Related blog post: https://developer.okta.com/blog/2020/01/09/java-rest-api-showdown
GitHub repo: https://github.com/oktadeveloper/okta-java-rest-api-comparison-example

  • Login to see the comments

  • Be the first to like this

Java REST API Comparison: Micronaut, Quarkus, and Spring Boot - jconf.dev 2020

  1. 1. Matt Raible | @mraible September 30, 2020 Java REST API Comparison Micronaut, Quarkus, and Spring Boot Photo by Matt Duncan on https://unsplash.com/photos/IUY_3DvM__w
  2. 2. Matt Raible Developer Advocate Okta @mraible I ❤ Java AND JavaScript! 🤓 https://jconf.dev
  3. 3. @mraible Who is Matt Raible? Father, Husband, Skier, Mountain Biker, Whitewater Rafter Bus Lover Web Developer and Java Champion Okta Developer Advocate Blogger on raibledesigns.com and developer.okta.com/blog @mraible
  4. 4. @mraible Today’s Agenda Why Java? Build { REST, GraphQL } APIs with Java Secure your APIs with OAuth 2.1 Build with Docker Go Native with GraalVM https://unsplash.com/photos/JsTmUnHdVYQ
  5. 5. @mraible Why Java? 25 Years of use, abuse, and improvements Open Source code is available; many popular open source frameworks and tools Hugely Popular and widely used by many enterprises and web-scale companies
  6. 6. @mraible Download the JDK from OpenJDK https://jdk.java.net/15 Or from AdoptOpenJDK https://adoptopenjdk.net Get Started with Java 15
  7. 7. @mraible Get Started with Java 15 Better yet, use SDKMAN! curl -s https://get.sdkman.io | bash sdk install java 15.0.0.hs-adpt
  8. 8. What’s New in Java 15 https://blogs.oracle.com/java-platform-group/the-arrival-of-java-15
  9. 9. https://developer.okta.com/blog/2020/01/09/java-rest-api-showdown Build REST APIs with Java
  10. 10. Serverless 💵 💸 https://unsplash.com/photos/glRqyWJgUeY
  11. 11. @mraible sdk install micronaut mn create-app com.okta.rest.app -b maven -f security-jwt Get Started with Micronaut
  12. 12. https://micronaut.io/launch
  13. 13. package com.okta.rest.controller; import io.micronaut.http.MediaType; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.Produces; import io.micronaut.security.annotation.Secured; import io.micronaut.security.rules.SecurityRule; import java.security.Principal; @Controller("/hello") public class HelloController { @Get @Secured(SecurityRule.IS_AUTHENTICATED) @Produces(MediaType.TEXT_PLAIN) public String hello(Principal principal) { return "Hello, " + principal.getName() + "!"; } }
  14. 14. micronaut.security.enabled=true micronaut.security.token.jwt.enabled=true micronaut.security.token.jwt.signatures.jwks.okta.url= https://dev-133337.okta.com/oauth2/default/v1/keys Micronaut JWT Security
  15. 15. micronaut.security.enabled=true micronaut.security.token.jwt.enabled=true micronaut.security.token.jwt.signatures.jwks.okta.url= https://dev-133337.okta.com/oauth2/default/v1/keys Micronaut JWT Security https://micronaut-projects.github.io/micronaut-security/latest/guide/#jwt
  16. 16. Install HTTPie (a better cURL) $ <tool> install httpie https://httpie.org
  17. 17. Test Micronaut with HTTPie https://httpie.org mvn mn:run http :8080/hello TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN... http :8080/hello Authorization:"Bearer $TOKEN"
  18. 18. Verify Micronaut API with HTTPie
  19. 19. @mraible Get Started with Quarkus mvn io.quarkus:quarkus-maven-plugin:1.8.1.Final:create -DprojectGroupId=com.okta.rest -DprojectArtifactId=quarkus -DclassName="com.okta.rest.quarkus.HelloResource" -Dpath="/hello" -Dextensions="jwt"
  20. 20. https://code.quarkus.io
  21. 21. package com.okta.rest.quarkus; import io.quarkus.security.Authenticated; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.SecurityContext; import java.security.Principal; @Path("/hello") public class HelloResource { @GET @Path("/") @Authenticated @Produces(MediaType.TEXT_PLAIN) public String hello(@Context SecurityContext context) { Principal userPrincipal = context.getUserPrincipal(); return "Hello, " + userPrincipal.getName() + "!"; } }
  22. 22. mp.jwt.verify.publickey.location= https://dev-133337.okta.com/ oauth2/default/v1/keys mp.jwt.verify.issuer=https:// dev-133337.okta.com/oauth2/ default MicroProfile JWT Security https://www.eclipse.org/community/eclipse_newsletter/2017/september/article2.php
  23. 23. mp.jwt.verify.publickey.location= https://dev-133337.okta.com/ oauth2/default/v1/keys mp.jwt.verify.issuer=https:// dev-133337.okta.com/oauth2/ default MicroProfile JWT Security https://www.eclipse.org/community/eclipse_newsletter/2017/september/article2.php
  24. 24. Test Quarkus with HTTPie https://httpie.org mvn compile quarkus:dev http :8080/hello TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN... http :8080/hello Authorization:"Bearer $TOKEN"
  25. 25. Verify Quarkus API with HTTPie
  26. 26. @mraible Get Started with Spring Boot http https://start.spring.io/starter.zip dependencies==web,okta packageName==com.okta.rest name=spring-boot type=maven-project -o spring-boot.zip
  27. 27. https://start.spring.io
  28. 28. package com.okta.rest.controller; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.security.Principal; @RestController public class HelloController { @GetMapping("/hello") public String hello(@AuthenticationPrincipal Principal principal) { return "Hello, " + principal.getName() + "!"; } }
  29. 29. Spring Security OAuth 2.0 Resource Server https://docs.spring.io/spring-security/site/docs/5.4.0/reference/html5/#oauth2resourceserver okta.oauth2.issuer=https://dev-133337.okta.com/ oauth2/default
  30. 30. Test Spring Boot with HTTPie https://httpie.org mvn spring-boot:run http :8080/hello TOKEN=eyJraWQiOiJxOE1QMjFNNHZCVmxOSkxGbFFWNlN... http :8080/hello Authorization:"Bearer $TOKEN"
  31. 31. Verify Spring Boot API with HTTPie
  32. 32. @mraible Startup PerformanceMilliseconds 0 525 1050 1575 2100 Micronaut Quarkus Spring Boot 1,878 658596 1,014 1,132 474 Dev Startup (mvn) Packaged Startup (java -jar)
  33. 33. @mraible Build GraphQL APIs with Java Why GraphQL? Does your favorite framework support GraphQL? Micronaut https://micronaut-projects.github.io/micronaut-graphql/latest/guide Quarkus https://quarkus.io/guides/microprofile-graphql Spring Boot https://github.com/leangen/graphql-spqr-spring-boot-starter
  34. 34. @mraible Secure your API with OAuth 2.0 https://aaronparecki.com/2019/12/12/21/its-time-for-oauth-2-dot-1
  35. 35. @mraible Secure your API with OAuth 2.1 https://oauth.net/2.1 PKCE is required for all clients using the authorization code flow Redirect URIs must be compared using exact string matching The Implicit grant is omitted from this specification The Resource Owner Password Credentials grant is omitted from this specification Bearer token usage omits the use of bearer tokens in the query string of URIs Refresh tokens for public clients must either be sender-constrained or one-time use
  36. 36. @mraible Authenticate with OpenID Connect (OIDC) What is OpenID Connect? Does your favorite framework support OIDC authentication? Micronaut https://guides.micronaut.io/micronaut-oauth2-okta/guide Quarkus https://quarkus.io/guides/security-openid-connect-web-authentication Spring Boot https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2login
  37. 37. @mraible What about Testing?
  38. 38. @mraible Build with Docker Create a Dockerfile FROM openjdk:15-alpine ARG JAR_FILE=target/*.jar COPY ${JAR_FILE} app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"]
  39. 39. @mraible Build with Docker Build your image docker build -t <tag-name> . Run your image docker run -i --rm -p 8080:8080 <tag-name>
  40. 40. @mraible Build with Docker: Jib Get Jibby with it! mvn verify jib:build Or build directly to your Docker daemon mvn verify jib:dockerBuild https://github.com/GoogleContainerTools/jib
  41. 41. @mraible Build with Docker Micronaut generates a Dockerfile Quarkus generates three Docker-related files Dockerfile.fast-jar Dockerfile.jvm Dockerfile.native Quarkus + Jib mvn quarkus:add-extension -Dextensions="container-image-jib"
  42. 42. @mraible Build with Docker Spring Boot 2.3+ has built-in support mvn spring-boot:build-image Uses layered JARs for for faster builds dependencies snapshot-dependencies resources application https://spring.io/blog/2020/01/27/creating-docker-images-with-spring-boot-2-3-0-m1
  43. 43. @mraible Use Micronaut CLI mn create-app ... -f graalvm mn feature-diff --features=graalvm mvn package ./docker-build.sh Go Native with GraalVM and Micronaut https://docs.micronaut.io/latest/guide/#graal
  44. 44. @mraible Go Native with GraalVM and Quarkus It’s built-in to Quarkus! mvn package -Pnative -Dquarkus.native.container-build=true Then build the image docker build -f src/main/docker/Dockerfile.native -t <tag- name> . And run it docker run -i --rm -p 8080:8080 <tag-name> https://quarkus.io/guides/building-native-image
  45. 45. @mraible Go Native with GraalVM and Spring Boot Upgrade to Spring 2.4.0-M2 <version>2.4.0-M2</version> Update configuration to avoid proxies https://tanzu.vmware.com/content/slides/the-path-towards-spring-boot-native-applications-2 @SpringBootApplication(proxyBeanMethods = false) public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
  46. 46. @mraible Go Native with GraalVM and Spring Boot Add Milestone repositories to your pom.xml <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </pluginRepository> </pluginRepositories>
  47. 47. @mraible Go Native with GraalVM and Spring Boot Configure your Spring Boot Maven Plugin <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <image> <env> <BP_BOOT_NATIVE_IMAGE>1</BP_BOOT_NATIVE_IMAGE> <BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS> -Dspring.native.remove-yaml-support=true -Dspring.spel.ignore=true --enable-https </BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS> </env> </image> </configuration> </plugin> https://www.graalvm.org/reference-manual/native-image/JCASecurityServices/
  48. 48. @mraible Go Native with GraalVM and Spring Boot Add Spring GraalVM dependency <dependency> <groupId>org.springframework.experimental</groupId> <artifactId>spring-graalvm-native</artifactId> <version>0.8.0</version> </dependency> Build the native application mvn spring-boot:build-image
  49. 49. @mraible Go Native with GraalVM and Spring Boot Run your native Spring Boot app! docker run -p 8080:8080 docker.io/library/demo:0.0.1-SNAPSHOT 💣 🐛 https://github.com/okta/okta-spring-boot/issues/192
  50. 50. @mraible Attempted Workaround for Okta + GraalVM Use Spring Security’s resource server <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-resource-server</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-jose</artifactId> </dependency> spring.security.oauth2.resourceserver.jwt.issuer-uri=https://...
  51. 51. @mraible Native Startup Performance Milliseconds 0 12.5 25 37.5 50 September 21, 2020 13 26 Micronaut Quarkus
  52. 52. @mraible Tests Run on a 2019 MacBook Pro
  53. 53. Community
  54. 54. @mraible Stack Overflow Tags 0 26250 52500 78750 105000 September 20, 2020 91,030 919732 Micronaut Quarkus Spring Boot
  55. 55. @mraible GitHub Stars 0 15000 30000 45000 60000 September 20, 2020 50,600 5,9004,100 Micronaut Quarkus Spring Boot
  56. 56. star-history.t9t.io/#micronaut-projects/micronaut-core&quarkusio/quarkus&spring-projects/spring-boot GitHub Star Growth
  57. 57. @mraible Jobs on Indeed (US) 0 1050 2100 3150 4200 September 20, 2020 3,745 1012 Micronaut Quarkus Spring Boot
  58. 58. Hot Frameworks https://hotframeworks.com
  59. 59. @mraible JHipster Support 🤓 Micronaut Blueprint - github.com/jhipster/generator-jhipster-micronaut - v0.3.8, 15 releases, 12 contributors, 289 commits // TODO: NoSQL, Reactive, Microservices, Graal VM native images Quarkus Blueprint - github.com/jhipster/jhipster-quarkus - v0.1.6, 7 releases, 7 contributors, 80 commits // TODO: Gradle, OAuth / OIDC, NoSQL, Reactive, Microservices
  60. 60. https://developer.okta.com/blog/2020/08/17/micronaut-jhipster-heroku
  61. 61. @mraible Action!
  62. 62. developer.okta.com/blog @oktadev
  63. 63. Curious about Microservice Security? https://developer.okta.com/blog/2020/03/23/microservice-security-patterns
  64. 64. Thanks! Keep in Touch raibledesigns.com @mraible Presentations speakerdeck.com/mraible Code github.com/oktadeveloper developer.okta.com
  65. 65. developer.okta.com

×