Hi, Habr! I present to your attention the translation of the article by Dmitry Kornilov
Helidon Takes Flight . I am not an Oracle employee, but I found an interesting article about a new, increasingly popular type of framework. So let's go ...
Today is a good day. Today we are introducing a new Java framework from the MicroProfile family for the implementation of microservices. The Helidon project is a new Java framework from Oracle.
Helidon, from the Greek translation of the swallow, a type of bird, according to Wikipedia, with a slim streamlined body and pointed wings, which provide greater maneuverability and ... a very effective flight. Ideal for flying in the clouds.
')
Introduction
Some time ago, work began on what the Helidon project is now. When we entered the cloud solutions market, and the microservice architecture became very popular for creating cloud services, we realized that the development expertise also needs to be expanded. It is possible to create microservices using Java EE, but it is better to have an infrastructure developed from scratch to create microservices. We wanted to create a lightweight set of libraries that do not require an application server and a cloud for Java SE applications. These libraries can be used separately from each other, but when used together, they will provide the developer with the creation of a microservice framework: initial configuration, security subsystem, and a web server.
Attempts are already being made to create standard microservice systems from MicroProfile. MicroProfile is quite popular in the Java EE / Jakarta EE community and provides a development experience similar to Java EE. We like the idea and we support this initiative. Helidon implements MicroProfile 1.1. We will continue to work on the introduction of new versions of MicroProfile and intend to support the relevant Jakarta EE standards in this area, as they have already been described.
Helidon is made in Oracle, so do not be surprised that there will be integration with the Oracle Cloud. They are not included in the original version, but will be added later. Helidon is already used by many Oracle internal projects and these integrations simplify the lives of our developers. We believe that it will simplify your life if you use Oracle Cloud. If not, these integrations are optional.
Classification
Java-frameworks for writing microservices are divided into several categories, from small to large:
- Microframeworks - simple, fun, with a deliberately limited set of features, for example: Spark, Javalin, Micronaut and others.
- MicroProfile - More familiar to Java EE developers, but a bit "heavier." Some of them are developed on top of Java EE application servers, for example: Thorntail (formerly Wildfly Swarm), OpenLiberty, Payara.
- Full Stack - Full -featured, such as Spring Boot.
Helidon comes in two versions and belongs to two categories: Microframeworks and MicroProfile.
- Helidon SE is a simple, functional, lightweight microframework designed in a modern reactive style. There is no "magic" in it. No special environment is required; JDK is used as it.
- Helidon MP is an implementation of Eclipse Microprofile that provides a development style familiar to Java EE / Jakarta EE developers.
Architecture
The Helidon architecture is shown below.
The components of Helidon SE are colored green, among which are Config, Security and RxServer.
Java EE / Jakarta EE components are colored gray, among which are JSON-P, JAX-RS / Jersey and CDI. They need a MicroProfile implementation. Helidon MP is a layer on top of the Helidon SE component. Additional components of Oracle Cloud services are colored red and can be used by both Helidon SE and Helidon MP components.
Examples of using
Installation
The easiest way to get started with Helidon is the Maven project in Java 8 (or higher), in which you specify Helidon bom-pom and minimal dependencies:
<dependencyManagement> <dependencies> <dependency> <groupId>io.helidon</groupId> <artifactId>helidon-bom</artifactId> <version>${helidon-version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ..... <dependency> <groupId>io.helidon.webserver</groupId> <artifactId>helidon-webserver-netty</artifactId> </dependency>
Helidon SE
Helidon SE is the basis for creating lightweight reactive microservices. Hello World example:
import io.helidon.webserver.Routing; import io.helidon.webserver.WebServer; ..... Routing routing = Routing.builder() .get("/hello", (req, res) -> res.send("Hello World")) .build(); WebServer.create(routing) .start();
In this case, we run the web server on an arbitrary (free) port and open access to / hello.
Add metrics
Now add the MicroProfile Metrics interface implementation for Helidon SE (without DI support, since this is not included in the SE). This will require the following dependencies:
<dependency> <groupId>io.helidon.metrics</groupId> <artifactId>helidon-metrics-se</artifactId> </dependency>
Implementation:
Now we have the following endpoint available:
- / metrics - all main metrics
- / metrics / application / helloCounter - metrics created by the "hello world" application
Heldon mp
Helidon MP is an Eclipse Microprofile implementation and microservice runtime environment.
To create a “Hello world” application that uses call number measurement metrics, you must create a JAX-RS resource class to handle requests:
@Path("hello") @RequestScoped
and then start the server with this resource:
Server.builder() .addResourceClass(HelloWorld.class) .build() .start();
You also need to create beans.xml in the src / main / resources / META-INF directory to activate CDI:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd" bean-discovery-mode="annotated"> </beans>
With this configuration, the web server on the default port (7001) and open access via / hello will be launched . . The following endpoints will be available:
- localhost : 7001 / hello - the “hello world” application itself
- localhost : 7001 / metrics - MicroProfile metrics
- localhost : 7001 / metrics / application / com.oracle.tlanger.HelloWorld.hello - metrics of our “hello world” application
- localhost : 7001 / health - MicroProfile Status Metrics
Plans
We have many plans that are suitable for a separate article.
Our short-term goal is to cover and introduce Helidon in the Java community. We plan to talk about Helidon at some conferences. Four reports are already scheduled on Helidon on Oracle Code One 2018. We also submitted an application for EclipseCon Europe 2018 and will participate in the Jakarta EE / MicroProfile Community Day. Training materials such as videos, use cases, articles, etc. already in development and will be published soon.
As for the technical side, we are working on the implementation of the next version of MicroProfile, support for GraalVM.
We are working on other cool things, but for now we cannot reveal all the cards. Stay with us, we will announce new features as soon as they are ready.
Sources
Perhaps it will be interesting to you:
- Initially, the name was J4C (Java for Cloud)
- Helidon is developed by a distributed team from Prague and the USA.
- Helidon is already used by more than ten projects in Oracle
- Some components of Helidon are still in development and will be publicly available after some time.