What is Quarkus ?

This tutorial cover the basics of what is Quarkus and how it can help you to create your Development layer on the top of a Kubernetes cluster.

Although, Microservices architecture is a trend on the rise, it is important to know that, without a valid framework to orchestrate them, the advantages of  Microservices can easily turn into a nightmare.

In this context, the arrival of Kubernetes has been a game changer in IT patterns. By orchestrating your services with Kubernetes, you can improve the efficiency and resource utilization by managing and scheduling your Microservices in a dynamic and resilient way.
So how Quarkus fits in this picture ? Quarkus, in a nutshell, is able to build lean Java code and native code from Java classes and create Container images out of it that you can run on the top of Kubernetes or OpenShift.

what is quarkus

Quarkus latest version

The latest available version of Quarkus is 2.7.0.CR1 which requires the following BOM:

<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>io.quarkus</groupId>
         <artifactId>quarkus-bom</artifactId>
         <version>2.7.0.CR1</version>
         <type>pom</type>
         <scope>import</scope>
      </dependency>
   </dependencies>
</dependencyManagement>

Native compilation or super fast Java code

Quarkus is a game changer as it leverages native code execution while
preserving the capability to still run your services with OpenJDK and use the Hotspot’s rich
dynamic code execution capabilities when required.

In order to compile Java code into native executables, you will need an extension of the
Virtual Machine called GraalVM. To be precise, GraalVM is an universal Virtual Machine
that facilitates compilation of bytecode of various languages

To learn more about Quarkus native compilation we recommend checking the following article: Building Container-ready native applications with Quarkus

Container ready platform

Thanks to its minimal footprint of Java and native applications, Quarkus is optimized to be run inside a Container. Out of the box, when you bootstrap a Quarkus project, you will get the following structure which already includes a set of Dockerfile both for JVM and native Container images:

src
├── main
│   ├── docker
│   │   ├── Dockerfile.jvm
│   │   ├── Dockerfile.legacy-jar
│   │   ├── Dockerfile.native
│   │   └── Dockerfile.native-distroless
│   ├── java
│   │   └── org
│   │       └── acme
│   │           └── getting
│   │               └── started
│   │                   ├── GreetingResource.java
│   │                   └── GreetingService.java
│   └── resources
│       ├── application.properties

As you can see, the following Dockerfiles are available:

  • The file Dockerfile.jvm can be used to build a Container image of Quarkus Java application based on the FastJar option which bundles all required libraries under the quarkus-app directory.
  • The file Dockerfile.native can be used to build a native Container image of Quarkus application.
  • The file Dockerfile.legacy-jar can be used to build a Container image of Quarkus Java application using the legacy approach (application libraries under the target folder).
  • The file Dockerfile.native-distroless can be used to build a distroless container that runs the Quarkus application in native (no JVM) mode

Leverage existing extensions

To simplify the start up or migration to Quarkus, you can leverage the best of breed of Java libraries you already know such as RestEasy, JPA/ Hibernate, Apache Kafka. On the top of that, you can add extensions which have been tailored for Quarkus such as Mutiny is a reactive programming model.

As an example, check the following articles to learn how to create a basic REST application using Quarkus and Hibernate:

Getting started with Quarkus and Hibernate

Extensive tooling

Despite its young age, Quarkus already features a wealth of tools to kickstart your applications. The first tool which has been added is Quarkus Maven plugin which lets you scaffold quickly an application with a set of extensions.

Besides it, most editors, such as IntelliJ Idea include a plugin to bootstrap Quarkus applications. See this article: Creating Quarkus projects using IntelliJ IDEA

Finally, you can use a powerful CLI which has been added in Quarkus 2.0 to simplify the creation/execution of applications, leveraging JBang tool: What’s new with Quarkus 2.0 and how to get started quickly

Reactive + Imperative

Most developers are familiar with the imperative programming model. In a nutshell, the imperative model is composed of a set of instructions which run in a sequence and modify an object’s state.
On the other hand, asynchronous programming has an inherent complexity in Java and lacks of a solid pattern for propagating asynchronous changes.

To fill this gap, a programming pattern called Reactive Programming has gained popularity due to its ability to combine the asynchronous programming model with data streams and the propagation of change.
Quarkus provides, out of the box, support for both programming models, so that you can take the benefits of both approaches in your IT organization.

// Imperative Programming Model
@Inject
MyService say;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
    return say.hello();
}

// Reactive Programming Model
@Channel("kafka") Multi<String> events;

@GET
@Produces(MediaType.SERVER_SENT_EVENTS)
public Multi<String> events() {
    return events;
}

Conclusion

In this article, we have covered the basics of what is QuarkusIO and how it can help you to kickstart your Java / native applications. Check here for more Quarkus resources in our site.