What is Quarkus (2023) ?

Quarkus is a framework you can use to develop Cloud-ready modern Java applications. Quarkus also allows to generate native executables from your Java application and can easily leverage the distribution as Container Images.

Microservice architectures and Quarkus

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 3.12.0.CR1 which requires the following BOM:

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

To get a taste of your first Quarkus application, you can head to the online application initializer that is available at: https://code.quarkus.io/

From there, you can select the extensions you want to include in your application and download the Maven/Gradle project.

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 perfect choice for running in a Container. Out of the box, when you bootstrap a new project, you will get the following structure:

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, several Dockerfiles are available out of the box:

  • Dockerfile.jvm : use it to build a Container image of a Java application based on the FastJar option which bundles all required libraries under the quarkus-app directory.
  • Dockerfile.native : use it to build a native Container image of your application.
  • Dockerfile.legacy-jar : use it to build a legacy Container image of your Java application (application libraries under the target folder).
  • Dockerfile.native-distroless : use it to build a distroless container that runs your application in native (no JVM) mode

Leverage existing extensions

To simplify the start up or migration to Quarkus, you can leverage the best of Java libraries you already know. For example, 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.

Extensive tooling

Despite its young age, there is already a wealth of tools to kickstart your applications. The first tool we want to mention is the 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 is available since Quarkus 2.0. The CLI simplifies 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.