Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Take MicroProfile to the Clouds with Quarkus by...

DevOps Gathering
March 11, 2020
180

Take MicroProfile to the Clouds with Quarkus by Dirk Weil

DevOps Gathering

March 11, 2020
Tweet

More Decks by DevOps Gathering

Transcript

  1. Dirk Weil GEDOPLAN GmbH, Bielefeld GEDOPLAN IT Consulting Software development,

    consulting, concepts, reviews GEDOPLAN IT Training Java, JEE, Tools etc. in Berlin, Bielefeld, on-site JEE since 1998 Speaker and author 2 gedoplan.de Take MicroProfile to the Clouds with Quarkus
  2. Java EE  Jakarta EE 2017: Project EE4J (Eclipse Enterprise

    for Java) Product name Jakarta EE Oracle keeps copyright Java EE Package names javax.* Jakarta EE 8 same code as Java EE 8 released Sept 10 2019 3 JEE gedoplan.de Take MicroProfile to the Clouds with Quarkus
  3. MicroProfile microprofile.io „Next step of Java EE / Jakarta EE

    evolution“ „… optimize Enterprise Java for a microservices architecture …“ 4 Config 1.3 Fault Tolerance 2.0 Health 2.0 JWT Authentication 1.1 Metrics 2.0.0 OpenAPI 1.1 OpenTracing 1.3 Rest Client 1.3 CDI 2.0 JAX-RS 2.1 JSON-B 1.0 JSON-P 1.1 gedoplan.de Take MicroProfile to the Clouds with Quarkus
  4. Microprofile runtimes: JEE application server 5 Application classes Config files

    (deployment descriptors, properties, …) JEE Server CDI runtime JPAruntime REST runtime Technical config * JRE build deploy run * Database, messaging security … Thin WAR small large gedoplan.de Take MicroProfile to the Clouds with Quarkus
  5. Microprofile Runtimes: „Micro“ frameworks 6 Application classes Config files *

    CDI runtime JPA runtime REST runtime JRE build run * Application properties, database, messaging security … Fat JAR JAR + Dependencies large gedoplan.de Take MicroProfile to the Clouds with Quarkus
  6. Quarkus Red Hats answer to Spring Boot Designated successor of

    Thorntail (aka WildFly Swarm) Optimized for quick start and short time to first response Hotspot and GraalVM https://quarkus.io/ 7 gedoplan.de Take MicroProfile to the Clouds with Quarkus
  7. Quarkus Core + extensions (= Maven dependencies) Project bootstrap via

    Maven plugin (or Gradle) 8 <dependencyManagement> <dependencies> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-bom</artifactId> <version>${quarkus.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy</artifactId> </dependency> <dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-junit5</artifactId> <scope>test</scope> </dependency> mvn io.quarkus:quarkus-maven-plugin:create \ -DprojectGroupId=de.gedoplan.showcase \ -DprojectArtifactId=quarkus-getting-started \ -DclassName="de.gedoplan.showcase.api.GreetingResource" \ -Dpath="/hello" gedoplan.de Take MicroProfile to the Clouds with Quarkus
  8. Quarkus Maven plugin for build Thin jar target/quarkus-getting-started-runner.jar Dependencies in

    target/lib/ Application start java –jar target/quarkus-getting-started-runner.jar 9 <plugins> <plugin> <groupId>io.quarkus</groupId> <artifactId>quarkus-maven-plugin</artifactId> <version>${quarkus.version}</version> <executions> <execution> <goals><goal>build</goal></goals> </execution> gedoplan.de Take MicroProfile to the Clouds with Quarkus
  9. Quarkus Development mode Hot reload triggered by REST/web request if

    source has changed 10 $ mvn quarkus:dev Listening for transport dt_socket at address: 5005 17:54:50,319 INFO [io.qua.dep.QuarkusAugmentor] (main) Beginning quarkus au 17:54:50,949 INFO [io.qua.resteasy] (build-1) Resteasy running without serv 17:54:50,949 INFO [io.qua.resteasy] (build-1) - Add quarkus-undertow to run 17:54:50,980 INFO [io.qua.dep.QuarkusAugmentor] (main) Quarkus augmentation 17:54:52,452 INFO [io.quarkus] (main) Quarkus started in 2.320s. Listening 17:54:52,452 INFO [io.quarkus] (main) Profile dev activated. Live Coding ac 17:54:52,454 INFO [io.quarkus] (main) Installed features: [cdi, resteasy] Demo quarkus-getting-started gedoplan.de Take MicroProfile to the Clouds with Quarkus
  10. MicroProfile Config Simple-to-use, injectable application configuration 11 @Path("/hello") public class

    GreetingResource { @Inject @ConfigProperty(name = "greeting.message") String message; @Inject @ConfigProperty(name = "greeting.name") Optional<String> name; greeting.message = Hola META-INF/microprofile-config.properties greeting.name = world System property GREETING_MESSAGE = Hello Environment variable Priority gedoplan.de Take MicroProfile to the Clouds with Quarkus
  11. Quarkus Config Additional configuration source application.properties Configuration profiles prod, dev,

    test extensible 12 greeting.message = Hello greeting.name = world %dev.greeting.name = developer %test.greeting.name = tester application.properties gedoplan.de Take MicroProfile to the Clouds with Quarkus
  12. MicroProfile Health REST endpoints for liveness and readiness /health/live and

    /health/ready Custom checks 13 @ApplicationScoped @Liveness public class LivenessCheck implements HealthCheck { @Inject LivenessSimulationService liveSvc; @Override public HealthCheckResponse call() { return HealthCheckResponse .named("livenessSimulation") .state(this.liveSrv.isLive()) .build(); { "status": "UP", "checks": [ { "name": "livenessSimulation", "status": "UP" } ] } gedoplan.de Take MicroProfile to the Clouds with Quarkus
  13. MicroProfile Metrics REST endpoints for measured data /metrics/{application|base|vendor}/name Formats: OpenMetrics

    (Prometheus), JSON Custom metrics 14 @GET @Timed(name = "personList", absolute = true) public List<Person> getAll() { @POST @Counted(name = "createPerson", absolute = true) public Response createPerson(Person Person) { @Gauge(name = "answerToLifeUniverseAndEverything", absolute = true, unit = MetricUnits.NONE) public long getAnswerToLifeUniverseAndEverything() { return 42; { "personList" : { "count": 5, "min": 1670500.0, "mean": 8909118.276749168, "max": 3.73522E7, … } } gedoplan.de Take MicroProfile to the Clouds with Quarkus
  14. MicroProfile Fault Tolerance Interceptors for resilience @Retry repeats calls after

    errors (=exceptions) @Timeout cancels hanging calls @Fallback supplies replacement value 15 @Retry(maxRetries = 4) public int doSomethingWithRetry() { @Timeout(1000) public int doSomethingWithTimeout() { private int return42() { return 42; } @Fallback(fallbackMethod = "return42") public int doSomethingWithFallback() { gedoplan.de Take MicroProfile to the Clouds with Quarkus
  15. MicroProfile Fault Tolerance Interceptors for resilience @CircuitBreaker suppresses calls after

    high error rate 16 @CircuitBreaker(failureRatio = 0.25, requestVolumeThreshold = 10) public int doSomethingWithCircuitBreaker() { closed open half-open too many errors ok delay error gedoplan.de Take MicroProfile to the Clouds with Quarkus
  16. Quarkus CDI / JPA CDI implementation ArC CDI 2.0 subset

    von CDI 2.0 no decorators, portable extensions, specialization, passivation ignore beans.xml contents not yet: interceptors on super classes, transactional observers Build time DI JPA implementation Hibernate Datasource config in application.properties DB extensions for PostgreSQL, H2, MariaDB, MS SQL, Derby 17 gedoplan.de Take MicroProfile to the Clouds with Quarkus
  17. Native Graal VM: Build native application target/xyz-runner Effectively used code

    only Non-Linux build in Docker container Starts within milliseconds, low memory consumption 18 gedoplan.de quarkus-getting-started $ mvn -Pnative,docker … [INFO] docker run -v //c/GEDOPLAN/projects/gedoplan/showcase/quar [quarkus-getting-started-runner:22] classlist: 4,939.89 ms … [quarkus-getting-started-runner:22] write: 576.45 ms [quarkus-getting-started-runner:22] [total]: 121,756.96 ms [INFO] Quarkus augmentation completed in 126125ms … [INFO] DOCKER> Built image sha256:0eb9a Take MicroProfile to the Clouds with Quarkus
  18. Additional features Websockets OpenAPI + Swagger UI Messaging (reactive +

    imperative) with AMQP, Kafka, JMS NoSQL Flyway OpenID, Keycloak, JWT RBAC Spring DI, Web, Data JPA, Security Scheduling Mail JSF … 19 gedoplan.de Take MicroProfile to the Clouds with Quarkus
  19. Conclusion MicroProfile (+ JEE) = Lightweight Enterprise Java Quarkus ~

    Spring Boot for JEE only small changes for JEE developers is fun to work with includes native execution aims at cloud, serverless young (started in 2018), but approved components 20 gedoplan.de Take MicroProfile to the Clouds with Quarkus
  20. More Slides: speakerdeck.com/dirkweil/take-microprofile- to-the-clouds-with-quarkus Demo projects: github.com/GEDOPLAN/quarkus-demo www.gedoplan-it-training.de Trainings in

    Berlin, Bielefeld, on-site new (2020): Microservices mit Quarkus - Grundlagen new (2020): Microservices mit Quarkus - Aufbau new (2019): Java DevOps: Development und Delivery mit Docker, Kubernetes und Jenkins  [email protected] @dirkweil 21 gedoplan.de Take MicroProfile to the Clouds with Quarkus