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

Java, Turbocharged!

Java, Turbocharged!

Over the last twenty years, there has been a paradigm shift in software development: from meticulously planned release cycles to an experimental way of working in which lead times are becoming shorter and shorter.

More and more companies are replacing Java in the Cloud with Go or Node, as they have much faster startup times combined with a much smaller memory footprint, which is especially important in a serverless environment.

After a short introduction, I will demonstrate how we can create a native executable with Quarkus, and how fast we can scale a large cluster of Quarkus containers in the cloud. Last but not least, I will show you how much fun it is to develop a REST + JPA based application with the help of Quarkus.

Marcus Biel

June 06, 2019
Tweet

More Decks by Marcus Biel

Other Decks in Programming

Transcript

  1. Build a new Project mvn io.quarkus:quarkus-maven-plugin:0.16.0:create \ -DprojectGroupId=com.redhat.developers \ -DprojectArtifactId=quarkus-demo

    \ -DclassName="com.redhat.developers.GreetingResource" \ -Dpath="/hello" http://bit.ly/DevTalksBucharest
  2. Build the Native Docker Image cd quarkus-demo mvn package -Pnative

    -Dnative-image.docker-build=true docker build -f src/main/docker/Dockerfile.native -t quarkus-demo/demo . docker run -i --rm -p 8080:8080 quarkus-demo/demo http://bit.ly/DevTalksBucharest
  3. Build the Image on Openshift oc new-build --binary --name=quarkus-demo -l

    app=quarkus-demo oc patch bc/quarkus-demo -p '{"spec":{"strategy":{"dockerStrategy":{"dockerfilePath":"s rc/main/docker/Dockerfile.native"}}}}' oc start-build quarkus-demo --from-dir=. --follow http://bit.ly/DevTalksBucharest
  4. Get the Route URL export URL="http://$(oc get route | grep

    quarkus-demo | awk '{print $2}')" echo $URL curl $URL/hello && echo http://bit.ly/DevTalksBucharest
  5. DeveloperResource package com.redhat.developers; @Path("/developers") public class DeveloperResource { @Path("/hello") @GET

    @Produces(MediaType.TEXT_PLAIN) public String hello() { return "hello"; } } http://bit.ly/DevTalksBucharest
  6. Quarkus on HotspotVM mvn package cd target du -sh *

    java -jar devtalks-1.0-SNAPSHOT-runner.jar ps ax -o pid,rss,command | numfmt --header --from-unit=1024 --to=iec --field 2 | grep -v grep | grep devtalks http://bit.ly/DevTalksBucharest
  7. Developer package com.redhat.developers; @Entity public class Developer extends PanacheEntity {

    private String name; public static Developer of(String name) { return new Developer(name); } public String getName() { return name; } private Developer(String name) { this.name = name; } private Developer() { //Panache only } } http://bit.ly/DevTalksBucharest
  8. DeveloperResource package com.redhat.developers; @GET @Produces(MediaType.APPLICATION_JSON) public List<Developer> developers() { return

    Developer.listAll(); } @Path("/new/{name}") @GET @Produces(MediaType.APPLICATION_JSON) @Transactional public Developer newDeveloper(@PathParam("name") String name) { Developer developer = Developer.of(name); developer.persist(); return developer; } http://bit.ly/DevTalksBucharest
  9. HelloClient package com.redhat.developers; @RegisterRestClient public interface HelloClient { @Path("/hello") @GET

    @Produces(MediaType.TEXT_PLAIN) String hello(); } http://bit.ly/DevTalksBucharest
  10. DeveloperResource package com.redhat.developers; @Path("/developers") public class DeveloperResource { @Inject @RestClient

    private HelloClient helloClient; @Path("/hello") @GET @Produces(MediaType.TEXT_PLAIN) @Fallback(fallbackMethod = "onFallback") public String helloWorld() { return helloClient.hello(); } private String onFallback() { return "Hello Bucharest!"; } } http://bit.ly/DevTalksBucharest