A new Java framework with GraalVM as the execution VM. It is developed by Red Hat.
The goal of Quarkus is to make Java a leading platform in Kubernetes and serverless environments while offering developers a unified reactive and imperative programming model to optimally address a wider range of distributed application architectures.
Quarkus' goal is to advance Java by providing developers with an integrated reactive and imperative programming model to accommodate a wide range of distributed application architectures in environments such as Kubernetes and serverless. Platform.
As stated in the official blog, it seems that it corresponds to the execution environment such as serverless where Spring and Play are slightly delayed.
Also, how to write with the conventional impeller model One of the great attractions is that it supports both reactive writing styles.
RxJava should allow you to achieve more flexible and less latency-sensitive application behavior.
It also supports existing libraries flexibly, so isn't it more than enough to create something quickly?
Besides using Hibernate ORM with default specifications It seems to support MariaDB and PostgreSQL.
By the way, you can also write in Kotlin.
For more information is here. ↓↓↓ https://quarkus.io/get-started/
macOS Mojave 10.14.3
--JJ1.8 with JAVA_HOME and above --Maven 3.5.3 and above
Since it is a Mac, install it with homebrew
brew update && brew install Maven
Check if it is installed
mvn --version
Success if it returns like this
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T03:41:47+09:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 1.8.0_162, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre
Default locale: ja_JP, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"
Install GraalVM (graalvm-ce-1.0.0-rc13-macos-amd64.tar.gz) ↓↓↓ https://github.com/oracle/graal/releases
Set GraalVM environment variable (GRAALVM_HOME) Please pass the path according to your shell. bash -> bashprofile zsh -> zshrc
GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-1.0.0-rc13-macos-amd64/Contents/Home
Go to the directory where you want to put the project
$ mvn io.quarkus:quarkus-maven-plugin:0.11.0:create \
-DprojectGroupId=jp.acme \
-DprojectArtifactId=getting-started \
-DclassName="org.acme.quickstart.GreetingResource" \
-Dpath="/hello"
This will launch an application built with Maven based on QUARKUS. The directory structure looks like this
Dockerfile for / docker Feeling to put the necessary Java code in / java Here there is GreetingResource.java and the contents are ↓↓
GreetingResource.java
package org.acme.quickstart;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class GreetingResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
Contains a simple code that returns "hello" when GET with / hello.
#Start in development mode
$ mvn compile quarkus:dev
Hot reload works when launched in development mode. (Hot reload is a function that compiles and reflects the difference each time a change is made)
Confirm if startup is successful
It will boot on port 8080 with the default settings, so hit curl to see if it returns hello
curl http://localhost:8080/hello
$ mvn package -Pnative -Dnative-image.docker-build=true
What is a native binary in the first place? It is a machine language that gives instructions necessary for execution, which is prepared for each execution machine. In other words, by using GraalVM, Linux will spit out machine language optimized for Linux.
By the way, this process takes some time. The original document also says that it gives me 15 minutes.
Let's build Docker when we get here. Click here for the command
$ docker build -f src/main/docker/Dockerfile -t <Image name> .
This will build the image using the Dockerfile included in the early application you just created. The inside of the Dockerfile looks like this
####
# Before building the docker image run:
#
# mvn package -Pnative -Dnative-image.docker-build=true
#
# Then, build the image with:
#
# docker build -f src/main/docker/Dockerfile -t quarkus/getting-started .
#
# Then run the container using:
#
# docker run -i --rm -p 8080:8080 quarkus/getting-started
#
###
FROM registry.fedoraproject.org/fedora-minimal
WORKDIR /work/
COPY target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
COPY target/*-runner /work/application
As you can see, it says that it will use the native binary under target.
$ docker run -i --rm -p 8080:8080 <Image name>
You can start the previous image by hitting this command. Port number 8080 At this time, the execution speed is displayed, but it is extremely fast.
It started in 0.005 seconds with me.
By using QUARKUS, it seems possible to develop applications that overcome the weakness of the JVM that supports Docker by default, which was the startup speed. Also, it can be said that it is suitable for large-scale development because a common development environment can be created based on the created Docker image.
I hope this will be an opportunity to create an environment where you can enjoy Java even more. I'm so interested in GraalVM that I'll write another article about GraalVM.
Recommended Posts