# Quarkus Framework Quarkus is a "supersonic" and "subatomic" Java application framework that is Kubernetes native. ## Pros ###### Sources: [Medium](https://betterprogramming.pub/which-java-microservice-framework-should-you-choose-in-2020-4e306a478e58) ### Kubernetes-Native Since we use k8s for container orchestration, having a k8s native application could optimize deployment. ### Subatomic * Small memory footprints ### Supersonic * Fast bootup time (Quarkus is GraalVM native) * Live reload ### Scalable * High rps ## Cons * Not suitable for apps that require high memory usage. ## Setup * Install [JDK 11](https://www.oracle.com/sg/java/technologies/javase-jdk11-downloads.html) * Install [GraalVM EE 21.X Core](https://www.oracle.com/downloads/graalvm-downloads.html) (Choose JDK 11 and macOS) * Make sure that you have GraalVM Core downloaded and installed. * Export the path to `gu`, which is GraalVM Updater tool to the `PATH` environment variable. By default, it's in: `/Library/Java/JavaVirtualMachines/graalvm-ee-<version>/Contents/Home/bin` * Run `gu install native-image` to get the latest version of the native image. When this was written, the version used was `GraalVM 21.1.0` * Exporting `JAVA_HOME` and `GRAALVM_HOME` * In MacOS X 10.5+ (Note that GraalVM path depends on its version) ```bash= export JAVA_HOME=$(usr/libexec/java_home) export GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ee-java11-21.1.0/Contents/Home echo "export JAVA_HOME=$JAVA_HOME" >> ~/.zshrc echo "export GRAALVM_HOME=$GRAALVM_HOME" >> ~/.zshrc source ~/.zshrc ``` * Install Quarkus Tools and Quarkus Run Configs IntelliJ plugins (Make sure that you're running IntelliJ CE/Ultimate 2019.x+) * Install `binutils` to debug native executable: ```bash= brew install binutils brew install gdb ``` * Reconfigure `File -> Project Structure -> Project SDK` to GraalVM. * Creating a Quarkus project: [Quarkus Base Project Generator](https://code.quarkus.io) or CLI: ```bash= mvn io.quarkus:quarkus-maven-plugin:1.13.6.Final:create \ -DprojectGroupId=co.ninjavan \ -DprojectArtifactId=getting-started \ -DclassName="co.ninjavan.getting.started.GreetingResource" \ -Dpath="/hello" ``` * Install dependencies * `cd getting-started` * `./mvnw install` * Running the server in dev mode (live reload) * `./mvnw quarkus:dev` * If it fails, make sure that in `pom.xml`: ```xml= <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>${compiler-plugin.version}</version> <configuration> <parameters>${maven.compiler.parameters}</parameters> <release>11</release> </configuration> </plugin> ``` * Building native executable * `./mvnw package -Pnative` * Running the executable * `./target/*-runner` ## Additional Reads ### API Documentation ###### Sources: [Quarkus OpenAPI & SwaggerUI](https://quarkus.io/guides/openapi-swaggerui) ### Dockerization ###### Sources: [MasterTheBoss: Building Container-ready Native apps](http://www.mastertheboss.com/soa-cloud/quarkus/building-container-ready-native-applications-with-quarkus), [Quarkus: K8s Extension](https://quarkus.io/guides/deploying-to-kubernetes), [Quarkus: Container image](https://quarkus.io/guides/container-image) ### Polyglot Programming in Quarkus ###### Sources: [GitHub example](https://github.com/marcinczeczko/quarkus-polyglot-example/blob/master/src/main/java/org/acme/polyglot/SvgRGraphService.java) ### GraalVM vs Mandrel ###### Source: [Quarkus](https://quarkus.io/guides/building-native-image) | Watch: [Role of GraalVM and Mandrel](https://www.youtube.com/watch?v=jUdx5Gq8Sqw&ab_channel=Quarkusio) Mandrel is a Java distribution developed by RedHat. It's a downstream distribution from GraalVM and is more catered towards OpenJDK. In relation to Quarkus framework, Mandrel is actually developed primarily to support developers to use Native Image GraalVM. However, Mandrel excludes some of the features that are not commonly used in Quarkus, in order to reduce the distribution size as compared to GraalVM CE/EE. One of the features that Mandrel excludes is polyglot programming, making it unsuitable for our projects.