MicroProfile-Anwendungen mit Quarkus
Expertenkreis Java, GEDOPLAN GmbH
31.09.2019
Dirk Weil
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
2gedoplan.deMicroprofile-Anwendungen mit Quarkus
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 4gedoplan.de
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
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.deMicroprofile-Anwendungen mit Quarkus
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.deMicroprofile-Anwendungen mit Quarkus
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 7gedoplan.de
Quarkus
Core
+ Extensions
(= Maven Dependencies)
Project Bootstrap mit
Maven Plugin
(oder Gradle)
Microprofile-Anwendungen mit Quarkus 8gedoplan.de
<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:0.26.1:create 
-DprojectGroupId=de.gedoplan.showcase 
-DprojectArtifactId=quarkus-getting-started 
-DclassName="de.gedoplan.showcase.api.GreetingResource" 
-Dpath="/hello"
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 9gedoplan.de
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<goals><goal>build</goal></goals>
</execution>
Quarkus
Development mode
Hot reload
bei REST/Web-Request
falls Quellcodeänderung
Microprofile-Anwendungen mit Quarkus 10gedoplan.de
$ 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 0.26.1 started in 2.320s. Lis
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
MicroProfile Config
Einfach nutzbare, injizierbare Anwendungskonfiguration
Microprofile-Anwendungen mit Quarkus 11gedoplan.de
@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
Quarkus Config
Zusätzliche Configuration Source application.properties
Configuration Profiles
prod, dev, test
erweiterbar (z. B. System Property quarkus.profile)
Microprofile-Anwendungen mit Quarkus 12gedoplan.de
greeting.message = Hello
greeting.name = world
%dev.greeting.name = developer
%test.greeting.name = tester
application.properties
Demo
quarkus-config
MicroProfile Health
REST endpoints für Liveness und Readiness
/health/live und /health/ready
Eigene Prüfungen ergänzbar
Microprofile-Anwendungen mit Quarkus 13gedoplan.de
@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"
}
]
}
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 14gedoplan.de
@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,
…
}
}
Quarkus Health / Metrics
MicroProfile-Implementierung SmallRye
Extension für Health: quarkus-smallrye-health
Extension für Metrics: quarkus-smallrye-metrics
Microprofile-Anwendungen mit Quarkus 15gedoplan.de
Demo quarkus-health
quarkus-metrics
MicroProfile Rest Client
Rest Client
Injizierbare REST clients
aus Interface generiert
konfigurierbare URL
Microprofile-Anwendungen mit Quarkus 16gedoplan.de
@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
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 17gedoplan.de
Demo
quarkus-rest-cdi-jpa
Test Support
Unterstützung für
JUnit 4 / 5
RestAssured
@QuarkusTest
Test Runner
Test Profile
u. a. anderer HTTP-Port
Microprofile-Anwendungen mit Quarkus 18gedoplan.de
Demo
quarkus-config
@QuarkusTest
public class GreetingResourceTest {
@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is("Hello tester!!!"));
}
Quarkus Native
Native executable via GraalVM
Startzeiten im ms-Bereich
Microprofile-Anwendungen mit Quarkus 19gedoplan.de
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
Fazit und Ausblick
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 (?)
ist noch in frühem Stadium
Ausblick:
(Reactive) Messaging
JSF Extension
Microprofile-Anwendungen mit Quarkus 20gedoplan.de
More
github.com/GEDOPLAN/quarkus-demo
Demo-Projekte
www.gedoplan-it-training.de
Trainings in Berlin, Bielefeld, inhouse
neu: JEE Microservice Foundation
neu: Java DevOps: Development und
Delivery mit Docker und Kubernetes
www.gedoplan-it-consulting.de
Reviews, Coaching, …
Blog
 dirk.weil@gedoplan.de
@dirkweil
21gedoplan.deMicroprofile-Anwendungen mit Quarkus

Microprofile-Anwendungen mit Quarkus

  • 1.
    MicroProfile-Anwendungen mit Quarkus ExpertenkreisJava, GEDOPLAN GmbH 31.09.2019 Dirk Weil
  • 2.
    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 2gedoplan.deMicroprofile-Anwendungen mit Quarkus
  • 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 Microprofile-Anwendungen mit Quarkus 3 JEE gedoplan.de
  • 4.
    MicroProfile microprofile.io „Next step ofJava EE / Jakarta EE evolution“ „… optimize Enterprise Java for a microservices architecture …“ Microprofile-Anwendungen mit Quarkus 4gedoplan.de 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
  • 5.
    Microprofile Runtimes: KlassischeApplication 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.deMicroprofile-Anwendungen mit Quarkus
  • 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.deMicroprofile-Anwendungen mit Quarkus
  • 7.
    Quarkus Red Hats Antwortauf Spring Boot Designierter Nachfolger von Thorntail (aka WildFly Swarm) Optimiert für kurze Startzeiten Hotspot und GraalVM https://quarkus.io/ Microprofile-Anwendungen mit Quarkus 7gedoplan.de
  • 8.
    Quarkus Core + Extensions (= MavenDependencies) Project Bootstrap mit Maven Plugin (oder Gradle) Microprofile-Anwendungen mit Quarkus 8gedoplan.de <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:0.26.1:create -DprojectGroupId=de.gedoplan.showcase -DprojectArtifactId=quarkus-getting-started -DclassName="de.gedoplan.showcase.api.GreetingResource" -Dpath="/hello"
  • 9.
    Quarkus Maven-Plugin für Build Thinjar target/quarkus-getting-started-runner.jar Dependencies in target/lib/ Anwendungsstart java –jar target/quarkus-getting-started-runner.jar Microprofile-Anwendungen mit Quarkus 9gedoplan.de <plugins> <plugin> <groupId>io.quarkus</groupId> <artifactId>quarkus-maven-plugin</artifactId> <version>${quarkus.version}</version> <executions> <execution> <goals><goal>build</goal></goals> </execution>
  • 10.
    Quarkus Development mode Hot reload beiREST/Web-Request falls Quellcodeänderung Microprofile-Anwendungen mit Quarkus 10gedoplan.de $ 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 0.26.1 started in 2.320s. Lis 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
  • 11.
    MicroProfile Config Einfach nutzbare,injizierbare Anwendungskonfiguration Microprofile-Anwendungen mit Quarkus 11gedoplan.de @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
  • 12.
    Quarkus Config Zusätzliche ConfigurationSource application.properties Configuration Profiles prod, dev, test erweiterbar (z. B. System Property quarkus.profile) Microprofile-Anwendungen mit Quarkus 12gedoplan.de greeting.message = Hello greeting.name = world %dev.greeting.name = developer %test.greeting.name = tester application.properties Demo quarkus-config
  • 13.
    MicroProfile Health REST endpointsfür Liveness und Readiness /health/live und /health/ready Eigene Prüfungen ergänzbar Microprofile-Anwendungen mit Quarkus 13gedoplan.de @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" } ] }
  • 14.
    MicroProfile Metrics REST endpointszur Lieferung von Messdaten /metrics/{application|base|vendor}/name Formate: OpenMetrics (Prometheus), JSON erweiterbar um eigene Messwerte Microprofile-Anwendungen mit Quarkus 14gedoplan.de @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, … } }
  • 15.
    Quarkus Health /Metrics MicroProfile-Implementierung SmallRye Extension für Health: quarkus-smallrye-health Extension für Metrics: quarkus-smallrye-metrics Microprofile-Anwendungen mit Quarkus 15gedoplan.de Demo quarkus-health quarkus-metrics
  • 16.
    MicroProfile Rest Client RestClient Injizierbare REST clients aus Interface generiert konfigurierbare URL Microprofile-Anwendungen mit Quarkus 16gedoplan.de @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
  • 17.
    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 17gedoplan.de Demo quarkus-rest-cdi-jpa
  • 18.
    Test Support Unterstützung für JUnit4 / 5 RestAssured @QuarkusTest Test Runner Test Profile u. a. anderer HTTP-Port Microprofile-Anwendungen mit Quarkus 18gedoplan.de Demo quarkus-config @QuarkusTest public class GreetingResourceTest { @Test public void testHelloEndpoint() { given() .when().get("/hello") .then() .statusCode(200) .body(is("Hello tester!!!")); }
  • 19.
    Quarkus Native Native executablevia GraalVM Startzeiten im ms-Bereich Microprofile-Anwendungen mit Quarkus 19gedoplan.de 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
  • 20.
    Fazit und Ausblick 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 (?) ist noch in frühem Stadium Ausblick: (Reactive) Messaging JSF Extension Microprofile-Anwendungen mit Quarkus 20gedoplan.de
  • 21.
    More github.com/GEDOPLAN/quarkus-demo Demo-Projekte www.gedoplan-it-training.de Trainings in Berlin,Bielefeld, inhouse neu: JEE Microservice Foundation neu: Java DevOps: Development und Delivery mit Docker und Kubernetes www.gedoplan-it-consulting.de Reviews, Coaching, … Blog  dirk.weil@gedoplan.de @dirkweil 21gedoplan.deMicroprofile-Anwendungen mit Quarkus