Helidon Takes Flight

Today is a great day. Today we introduce a new Java microservices frameworks and a new member of MicroProfile family. Please welcome Project Helidon — a new Java open source microservices framework from Oracle.

Helidon is a Greek word for “swallow”, a type of bird that according to Wikipedia has “a slender, streamlined body and long pointed wings, which allow great manoeuvrability and… very efficient flight”. Perfect for darting through the clouds.

Overview

The work on what would become the Helidon Project started some time ago. When we entered the cloud world, and microservices architecture started to become very popular for creating cloud services, we realized that the development experience also needed to change. It’s possible to build microservices using Java EE, but it’s better to have a framework designed from the ground up for building microservices. We wanted to create a lightweight set of libraries that didn’t require an application server and could be used in Java SE applications. These libraries could be used separately from each other, but when used together would provide everything a developer needs to create a microservice: configuration, security, and a web server.

There are already some efforts to build standard microservices frameworks from MicroProfile. MicroProfile is quite popular in the Java EE/Jakarta EE community and provide a development experience similar to Java EE. We like the idea and support the initiative. Helidon implements MicroProfile 1.1. We will continue working on implementing new versions of MicroProfile and intend to support relevant Jakarta EE standards in this area as they are defined.

Helidon is made by Oracle, so don’t be surprised that there will be some useful Oracle Cloud integrations. These are not included in the initial version, but will be added later. Helidon is already used by many internal Oracle projects and these integrations simplify our developers’ lives big time. We believe that will simplify your life as well if you use Oracle Cloud. If not, these integrations are optional.

Landscape

helidon_landscape.png

Java Frameworks for writing microservices fall into a few categories. From smaller to larger:

  • Microframeworks
    Simple, fun, intentionally small feature set. Examples are Spark, Javalin, Micronaut, etc.
  • MicroProfile
    Friendly to Java EE developers but a bit heavier. Some of them are build on top of fully featured Java EE application servers. Examples are Thorntail (was Wildfly Swarm), OpenLiberty, Payara.
  • Full Stack
    Fuller features set such as Spring Boot.

Helidon comes in two flavours and covers two categories — Microframeworks and MicroProfile. It’s up to a developer to choose what to use in their applications.

  • Helidon SE — simple, functional, lightweight microframework developed in a modern reactive way. There is no injection “magic”. No special runtime required. JDK is used as runtime.
  • Helidon MP — Eclipse Microprofile implementation providing development experience familiar to Java EE/Jakarta EE developers.

Architecture

Helidon’s high level architecture is shown on the picture below.

  • Helidon SE components are marked green. These are Config, Security and RxServer.
  • The Java EE/Jakarta EE components we use are marked grey. These are JSON-P, JAX-RS/Jersey and CDI. These components are required for MicroProfile implementation.
  • Helidon MP is a thin layer on top of Helidon SE components.
  • Oracle Cloud services components are marked red and used in both Helidon SE and Helidon MP.

Usage and Samples

Setup

The easiest way to start using Helidon is if you use a Maven project with Java 8 (or higher version) and configure the Helidon bom-pom:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-bom</artifactId>
<version>${helidon-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
view raw pom.xml hosted with ❤ by GitHub

Helidon SE

Helidon SE is the base to build lightweight reactive microservices.

A Hello world implementation:

Routing routing = Routing.builder()
.get("/hello", (req, res) -> res.send("Hello World"))
.build();
WebServer.create(routing)
.start();
view raw HelloWorld.java hosted with ❤ by GitHub

This would start webserver on a random (free) port and expose endpoint /hello.

Imports:

import io.helidon.webserver.Routing;
import io.helidon.webserver.WebServer;
view raw HelloWorld.java hosted with ❤ by GitHub

Dependency needed to start this example (version not required if you used bom-pom):

<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-netty</artifactId>
</dependency>
view raw pom.xml hosted with ❤ by GitHub

Adding metrics to SE

We have provided an implementation of MicroProfile Metrics interfaces also for Helidon SE (without support for injection, as that is not included in SE).

Updated source code with metrics:

// create metric registry
MetricsSupport metricsSupport = MetricsSupport.create();
// get the registry
MetricRegistry registry = RegistryFactory
.getRegistryFactory()
.get()
.getRegistry(MetricRegistry.Type.APPLICATION);
// create a counter
Counter helloCounter = registry.counter("helloCounter");
Routing routing = Routing.builder()
// register metric support with web server
.register(metricsSupport)
.get("/hello", (req, res) -> {
// increase counter
helloCounter.inc();
res.send("Hello World");
})
.build();
WebServer.create(routing)
.start();
view raw HelloWorld.java hosted with ❤ by GitHub

This requires a new dependency:

<dependency>
<groupId>io.helidon.metrics</groupId>
<artifactId>helidon-metrics-se</artifactId>
</dependency>
view raw pom.xml hosted with ❤ by GitHub

New endpoints are available:

  • /metrics
    All metrics (base, vendor and application)
  • /metrics/application/helloCounter
    The metric created in our hello world application

Helidon MP

Helidon MP is Eclipse Microprofile implementation and a runtime for microservices.

A Hello world implementation that uses metrics to meter the invocations.

You must create a JAX-RS resource class to process your requests:

@Path("hello")
@RequestScoped //allows us to use CDI injection
public class HelloWorld {
@GET
@Metered
public String hello() {
return "Hello World";
}
}
view raw HelloWorld.java hosted with ❤ by GitHub

And then start the server with this resource:

Server.builder()
.addResourceClass(HelloWorld.class)
.build()
.start();
view raw HelloWorld.java hosted with ❤ by GitHub

You also need to create beans.xml file in the src/main/resources/META-INF directory to trigger CDI injection in this project:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
xmlns="http://xmlns.jcp.org/xml/ns/javaee&quot;
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd&quot;
bean-discovery-mode="annotated">
</beans>
view raw beans.xml hosted with ❤ by GitHub

This would start a webserver on the default port (7001) and expose endpoint /hello.

The following endpoints are available:

Plans

We have so many plans, I could write a separate article about them.

Our short term goal is to advertise Helidon in the Java community. We are planning to talk about Helidon at some conferences. We have four Helidon-related Oracle Code One 2018 talks planned. We have also submitted talks to EclipseCon Europe 2018 and will participate in the Jakarta EE/MicroProfile Community Day there. Some learning materials such as screen casts and YouTube videos are also on the way.

From the technical perspective, we are working on implementing the next MicroProfile versions very soon. We are also working on Oracle GraalVM support, which looks like a great feature for Helidon SE users.

We are working on some other cool stuff and features, but I can’t show all my cards now. Stay tuned, we will announce new features as soon as the are ready.

Useful Links

You may find it interesting

  • The original internal name of the project was J4C (Java for Cloud).
  • The Helidon team consists of two smaller teams in Prague (Czech Republic) and in the U.S.
  • Helidon is used in more than 10 projects within Oracle.
  • Some Helidon components are still in development and not open sourced yet.

Original article on my Medium blog.

3 thoughts on “Helidon Takes Flight

  1. Congratulations!
    I’ll just give a presentation in a couple of weeks on microprofile.
    Now I will add Helidon to the presentation 🙂

    Like

Leave a comment