#12 Helidon 2.2 – Fast, Secure & Lightweight microservices framework
Oracle Helidon framework to develop fast and lightweight microservices
Helidon framework (Open sourced by Oracle ) to develop fast, lightweight and secure microservices
Microservices – also known as the microservice architecture – is an architectural style that structures an application as a collection of loosely coupled services, which implement business capabilities. The microservice architecture enables the continuous delivery/deployment of large, complex applications. It also enables an organization to evolve its technology stack. There are many framework used for writing microservices like Spring boot, Micronauts, micronaut, Quarkus and Helidon. In this article we will talk about Helidon framework and how we can write an effective, fast and lightweight microservice using Oracle Helidon.
Page Contents
What is Helidon ?
Helidon is a microservices framework developed by Oracle internal projects under the name J4C(Java for Cloud). Now Helidon framework has been open sourced by Oracle.
Helidon SE and Helidon MP
Currently there are two programming model supported by this framework – Helidon SE and Helidon MP. Helidon SE is designed for microservices that support reactive programming model. Helidon MP is designed to support Eclipse MicroProfile runtime that allow Jakarta EE community to run portable microservices.
Helidon architecture and how Helidon SE & Helidon MP fit together
The relationship between Helidon SE and Helidon MP is shown in the architecture diagram
Helidon SE quickstart
Prerequisite
- Maven
- Java > 11
- Run following command from cmd/bash
mvn -U archetype:generate -DinteractiveMode=false -DarchetypeGroupId=io.helidon.archetypes -DarchetypeArtifactId=helidon-quickstart-se -DarchetypeVersion=2.2.2 -DgroupId=com.teknonauts.examples -DartifactId=helidon-example-se -Dpackage=com.teknonauts.examples.helidon.se
2. It will generate project: helidon-example-se. Import this project as an existing maven project in your workspace. Structure will look like this
3. Understand main method in Main.java
WebServer server = WebServer.builder(createRouting(config))
.config(config.get("server"))
.addMediaSupport(JsonpSupport.create())
.build();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
server.start()
.thenAccept(ws -> {
System.out.println(
"WEB server is up! http://localhost:" + ws.port() + "/greet");
ws.whenShutdown().thenRun(()
-> System.out.println("WEB server is DOWN. Good bye!"));
})
.exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
4. Now run the main method and check the services –
http://localhost:8080/greet/{name}
5. You can also run below command to generate jar and run the server
mvn package
java -jar target/helidon-example-se.jar
6. Build and Run Docker Image
docker build -t helidon-example-se .
docker run --rm -p 8080:8080 helidon-example-se:latest
Helidon MP quickstart
Prerequisite
- Maven,
- Java > 11
- Run following command from cmd/bash
mvn -U archetype:generate -DinteractiveMode=false -DarchetypeGroupId=io.helidon.archetypes -DarchetypeArtifactId=helidon-quickstart-mp -DarchetypeVersion=2.2.2 -DgroupId=com.teknonauts.examples -DartifactId=helidon-example-mp -Dpackage=com.teknonauts.examples.helidon.mp
2. It will generate project: helidon-example-mp. Import this project as an existing maven project in your workspace. Structure will look like this
3. Package the project with below command
mvn package
4. Run the below command to start the server
java -jar target/helidon-example-mp.jar
5. Observe below API and related code
http://localhost:8080/greet/{name}
6. Health Matrics
Health
curl -s -X GET http://localhost:8080/health
Matrics in Prometheus format
curl -s -X GET http://localhost:8080/metrics
7. Build and Run docker image
docker build -t helidon-example-mp .
docker run --rm -p 8080:8080 helidon-example-mp:latest
Conclusion Helidon SE vs Helidon MP
Helidon SE | Helidon MP |
Helidon SE gives you full transparency and puts you in control. | Helidon MP is built on top of the Helidon libraries and provides platform definition that is familiar to enterprise Java developers. |
Microframework model with a very small footprint and limited functionality (~7 MB) | Eclipse MicroProfile implementation; slightly larger footprint than SE (~13 MB) |
Functional style is reactive non-blocking | Declarative style with dependency injection |
Transparent “no magic” development experience; pure java application development with no annotations and no dependency injections | Jakarta EE microprofile development experience; all Jakarta components (CDI, JAX-RS, JSON-P/B) |
Learn more about Helidon SE. | Learn more about Helidon MP. |
Helidon SE & Helidon MP example code available on our git page
https://github.com/teknonauts/helidon
Next topic to cover
In this article I have covered basics of helidon framework and how to create simple project in both categories. Below are the two topics I will cover in next post of this series
- GraalVM and its benefit. GraalVM support in Helidon framework
- Non-blocking Database client in Helidon
Reference
- Helidon.io
- Example from baeldung
- Microprofile.io — https://microprofile.io/
Explore more at Teknonauts.com
Awadhesh Pratap Dwivedi is an IT industry leader with over 13+ years of experience. He is excellent at providing an easy solution to complex business problems with his tremendous problem-solving skills. Currently, he is working with Oracle as a Principal Solution Engineer.