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

Mit MicroProfile und Quarkus in die Wolken

Mit MicroProfile und Quarkus in die Wolken

Slides zum Vortrag im Rahmen des Treffpunkt Semicolon der GFU Cyrus AG

Dirk Weil

May 26, 2020
Tweet

More Decks by Dirk Weil

Other Decks in Education

Transcript

  1. Mit MicroProfile und Quarkus in die Wolken Treffpunkt Semicolon, GFU

    Cyrus AG 26.05.2020 Dirk Weil, GEDOPLAN GmbH
  2. Dirk Weil GEDOPLAN GmbH, Bielefeld GEDOPLAN IT Consulting Softwareentwicklung, Beratung,

    Konzepte, Reviews GEDOPLAN IT Training Java, JEE, Tools u.v.a.m. in Berlin, Bielefeld, on-site JEE seit 1998 Speaker und Autor 2 gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  3. Java EE  Jakarta EE 2017: Projekt EE4J (Eclipse Enterprise

    for Java) Produktname Jakarta EE Oracle behält Namens- und Urheberrechte Java EE Paketnamen javax.* Jakarta EE 8 codegleich zu Java EE 8 Release 10.09.2019 3 JEE gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  4. MicroProfile microprofile.io „Next step of Java EE / Jakarta EE

    evolution“ „… optimize Enterprise Java for a microservices architecture …“ 4 Config Fault Tolerance Health JWT Authentication Metrics OpenAPI OpenTracing Rest Client CDI JAX-RS JSON-B JSON-P gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  5. Microprofile Runtimes: Klassische Application Server 5 Anwendungsklassen Konfigurationsfiles (Deployment Descriptors,

    Properties, …) JEE Server CDI Runtime JPA Runtime REST Runtime Technische Konfiguration * JRE build deploy run * DB-Verbindungen, Messaging Security … Thin WAR klein groß gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  6. Microprofile Runtimes: „Micro“ Frameworks 6 Anwendungsklassen Konfigurationsfiles * CDI Runtime

    JPA Runtime REST Runtime JRE build run * Anwendungsparameter, DB-Verbindungen, Messaging Security … Fat JAR JAR + Dependencies groß gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  7. Quarkus Red Hats Antwort auf Spring Boot Designierter Nachfolger von

    Thorntail (aka WildFly Swarm) Optimiert für kurze Startzeiten Hotspot und GraalVM https://quarkus.io/ 7 gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  8. Quarkus Core + Extensions (= Maven Dependencies) Project Bootstrap mit

    Maven Plugin (oder 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 Mit MicroProfile und Quarkus in die Wolken
  9. Quarkus Maven-Plugin für Build Thin jar target/quarkus-getting-started-runner.jar Dependencies in target/lib/

    Anwendungsstart 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 Mit MicroProfile und Quarkus in die Wolken
  10. Quarkus Development mode Hot reload bei REST/Web-Request falls Quellcodeänderung 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 Mit MicroProfile und Quarkus in die Wolken
  11. MicroProfile Config Einfach nutzbare, injizierbare Anwendungskonfiguration 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 Mit MicroProfile und Quarkus in die Wolken
  12. Quarkus Config Zusätzliche Configuration Source application.properties Configuration Profiles prod, dev,

    test erweiterbar (z. B. System Property quarkus.profile) Seit 1.1.x auch application.yaml 12 greeting.message = Hello greeting.name = world %dev.greeting.name = developer %test.greeting.name = tester application.properties Demo quarkus-config gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  13. MicroProfile Health REST endpoints für Liveness und Readiness /health/live und

    /health/ready Eigene Prüfungen ergänzbar 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 Mit MicroProfile und Quarkus in die Wolken
  14. MicroProfile Metrics REST endpoints zur Lieferung von Messdaten /metrics/{application|base|vendor}/name Formate:

    OpenMetrics (Prometheus), JSON erweiterbar um eigene Messwerte 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 Mit MicroProfile und Quarkus in die Wolken
  15. MicroProfile Rest Client Rest Client Injizierbare REST clients aus Interface

    generiert konfigurierbare URL 15 @Path("v2") @RegisterRestClient public interface CountryApi { @GET @Path("all") @Produces("application/json") Collection<Country> getAll(); de.gedoplan.showcase.….CountryApi/mp-rest/url=http://restcountries.eu/rest META-INF/microprofile-config.properties @Path("country") @ApplicationScoped public class CountryResource { @Inject @RestClient CountryApi countryClient; @GET @Path("count") @Produces(MediaType.APPLICATION_JSON) public int getCount() { return countryClient.getAll().size(); gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  16. MicroProfile Fault Tolerance Interceptors für Resilience @Retry wiederholt Aufruf bei

    Fehler (=Exception) @Timeout bricht langsame Aufrufe ab @Fallback liefert Ersatzwert 16 @Retry(maxRetries = 4) public int doSomethingWithRetry() { @Timeout(1000) public int doSomethingWithTimeout() { private int return42() { return 42; } @Fallback(fallbackMethod = "return42") public int doSomethingWithFallback() { gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  17. MicroProfile Fault Tolerance Interceptors für Resilience @CircuitBreaker unterdrückt Aufrufe bei

    hoher Fehlerrate 17 @CircuitBreaker(failureRatio = 0.25, requestVolumeThreshold = 10) public int doSomethingWithCircuitBreaker() { closed open half-open zu viele Fehler ok Delay Fehler gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  18. Quarkus CDI / JPA CDI-Implementierung ArC Subset von CDI 2.0

    no decorators, portable extensions, specialization, passivation ignore beans.xml contents Build time DI JPA-Implementierung Hibernate Datasource-Konfiguration in application.properties DB-Extensions für PostgreSQL, H2, MariaDB, MS SQL, Derby 18 Demo quarkus-rest-cdi-jpa gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  19. Test Support Unterstützung für JUnit 4 / 5 RestAssured @QuarkusTest

    Test Runner Test Profile u. a. anderer HTTP-Port 19 Demo quarkus-config @QuarkusTest public class GreetingResourceTest { @Test public void testHelloEndpoint() { given() .when().get("/hello") .then() .statusCode(200) .body(is("Hello tester!!!")); } gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  20. Native Graal VM: Erstellung native application target/xyz-runner Nur tatsächlich genutzter

    Code Build auf Non- Linux im Docker Container Startzeit im ms-Bereich, Memory consumption im (kleinen) MB-Bereich 20 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 Mit MicroProfile und Quarkus in die Wolken
  21. Weitere Features Websockets OpenAPI + Swagger UI Messaging (reactive +

    imperative) mit AMQP, Kafka, JMS NoSQL Flyway Security mit OpenID, Keycloak, JWT RBAC Spring DI, Web, Data JPA, Security Scheduling Mail JSF … 21 gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  22. Fazit MicroProfile (+ JEE) = Lightweight Enterprise Java Quarkus ~

    Spring Boot für JEE kaum Umdenken notwendig für JEE-Entwickler macht Spaß native Ausführung möglich Richtung: Cloud, serverless (?) 22 gedoplan.de Mit MicroProfile und Quarkus in die Wolken
  23. More github.com/GEDOPLAN/quarkus-demo Demo-Projekte gfu.net Trainings in Köln, Berlin, inhouse neu

    (2020): Microservices mit Quarkus – Grundlagen/Aufbau/kompakt neu (2019): Java DevOps: Development und Delivery mit Docker, Kubernetes und Jenkins www.gedoplan-it-consulting.de Reviews, Coaching, … Blog  [email protected] @dirkweil 23 gedoplan.de Mit MicroProfile und Quarkus in die Wolken