Share
Embed
MicroProfile-Anwendungen mit Quarkus
Slides zum Vortrag im Rahmen der JUG Ostfalen am 06.02.2020.
"Supersonic Subatomic Java" verspricht der neue Stern am Himmel der Microservice-Frameworks namens Quarkus. Tatsächlich lassen sich mit Quarkus schnell und einfach Services erstellen, die klein, performant und reaktiv sind und dennoch das JEE-Programm-Modell weiter nutzen. Basis ist das Eclipse MicroProfile, das neben einem Subset von Jakarta EE 8 diverse Erweiterungen für verteilte (Micro?) Services enthält. Dieser Vortrag gibt einen Überblick über die Entwicklung mit Quarkus inklusive einiger Demos.
Dirk Weil
February 06, 2020
Transcript
24 slides
-
Dirk Weil GEDOPLAN GmbH, Bielefeld GEDOPLAN IT Consulting Consulting, coaching,
concepts, reviews, development GEDOPLAN IT Training & partner Java, JEE, tools trainings in Berlin, Bielefeld, Köln, on-site JEE since 1998 Speaker and author 2 Microprofile-Anwendungen mit Quarkus gedoplan.de -
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 Microprofile-Anwendungen mit Quarkus 3 JEE gedoplan.de -
MicroProfile microprofile.io „Next step of Java EE / Jakarta EE
evolution“ „… optimize Enterprise Java for a microservices architecture …“ Microprofile-Anwendungen mit Quarkus 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 -
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ß Microprofile-Anwendungen mit Quarkus gedoplan.de -
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ß Microprofile-Anwendungen mit Quarkus gedoplan.de -
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/ Microprofile-Anwendungen mit Quarkus 7 gedoplan.de -
Quarkus Core + Extensions (= Maven Dependencies) Project Bootstrap mit
Maven Plugin (oder Gradle) Microprofile-Anwendungen mit Quarkus 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 -
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 Microprofile-Anwendungen mit Quarkus 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 -
Quarkus Development mode Hot reload bei REST/Web-Request falls Quellcodeänderung Microprofile-Anwendungen
mit Quarkus 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 -
MicroProfile Config Einfach nutzbare, injizierbare Anwendungskonfiguration Microprofile-Anwendungen mit Quarkus 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 -
Quarkus Config Zusätzliche Configuration Source application.properties Configuration Profiles prod, dev,
test erweiterbar (z. B. System Property quarkus.profile) Microprofile-Anwendungen mit Quarkus 12 greeting.message = Hello greeting.name = world %dev.greeting.name = developer %test.greeting.name = tester application.properties Demo quarkus-config gedoplan.de -
MicroProfile Health REST endpoints für Liveness und Readiness /health/live und
/health/ready Eigene Prüfungen ergänzbar Microprofile-Anwendungen mit Quarkus 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 -
MicroProfile Metrics REST endpoints zur Lieferung von Messdaten /metrics/{application|base|vendor}/name Formate:
OpenMetrics (Prometheus), JSON erweiterbar um eigene Messwerte Microprofile-Anwendungen mit Quarkus 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 -
Quarkus Health / Metrics MicroProfile-Implementierung SmallRye Extension für Health: quarkus-smallrye-health
Extension für Metrics: quarkus-smallrye-metrics Microprofile-Anwendungen mit Quarkus 15 Demo quarkus-health quarkus-metrics gedoplan.de -
MicroProfile Rest Client Rest Client Injizierbare REST clients aus Interface
generiert konfigurierbare URL Microprofile-Anwendungen mit Quarkus 16 @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(); Demo quarkus-rest-client gedoplan.de -
MicroProfile Fault Tolerance Interceptors für Resilience @Retry wiederholt Aufruf bei
Fehler (=Exception) @Timeout bricht langsame Aufrufe ab @Fallback liefert Ersatzwert Microprofile-Anwendungen mit Quarkus 17 @Retry(maxRetries = 4) public int doSomethingWithRetry() { @Timeout(1000) public int doSomethingWithTimeout() { private int return42() { return 42; } @Fallback(fallbackMethod = "return42") public int doSomethingWithFallback() { gedoplan.de -
MicroProfile Fault Tolerance Interceptors für Resilience @CircuitBreaker unterdrückt Aufrufe bei
hoher Fehlerrate Microprofile-Anwendungen mit Quarkus 18 @CircuitBreaker(failureRatio = 0.25, requestVolumeThreshold = 10) public int doSomethingWithCircuitBreaker() { Demo quarkus-fault-tolerance closed open half-open zu viele Fehler ok Delay Fehler gedoplan.de -
Quarkus CDI / JPA CDI-Implementierung ArC 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-Implementierung Hibernate Datasource-Konfiguration in application.properties DB-Extensions für PostgreSQL, H2, MariaDB, MS SQL, Derby Microprofile-Anwendungen mit Quarkus 19 Demo quarkus-rest-cdi-jpa gedoplan.de -
Test Support Unterstützung für JUnit 4 / 5 RestAssured @QuarkusTest
Test Runner Test Profile u. a. anderer HTTP-Port Microprofile-Anwendungen mit Quarkus 20 Demo quarkus-config @QuarkusTest public class GreetingResourceTest { @Test public void testHelloEndpoint() { given() .when().get("/hello") .then() .statusCode(200) .body(is("Hello tester!!!")); } gedoplan.de -
Quarkus Native Native executable via GraalVM Startzeiten im ms-Bereich Microprofile-Anwendungen
mit Quarkus 21 Demo getting-started (aus Quarkus-Guide) docker build -f src/main/docker/Dockerfile.multistage \ -t quarkus-quickstart/getting-started . docker run -i --rm -p 8080:8080 \ quarkus-quickstart/getting-started gedoplan.de -
Weitere Features OpenAPI + Swagger UI Messaging (reactive + imperative)
mit AMQP, Kafka, JMS Flyway Security mit OpenID, Keycloak, JWT RBAC Spring DI, Web, Data JPA, Security Scheduling Mail JSF … Microprofile-Anwendungen mit Quarkus 22 gedoplan.de -
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 (?) frühes Stadium, aber bewährte Komponenten Microprofile-Anwendungen mit Quarkus 23 gedoplan.de -
More github.com/GEDOPLAN/quarkus-demo Demo-Projekte www.gedoplan-it-training.de Trainings in Berlin, Bielefeld, inhouse neu:
Microservices mit Quarkus - Grundlagen neu: Microservices mit Quarkus - Aufbau neu: Java DevOps: Development und Delivery mit Docker, Kubernetes und Jenkins www.gedoplan-it-consulting.de Reviews, Coaching, … Blog [email protected] @dirkweil 24 Microprofile-Anwendungen mit Quarkus gedoplan.de