Helidon is a set of Java libraries for developing microservices. It provides a lightweight, high-performance platform for building microservices applications in Java, with support for both reactive and imperative programming models. Helidon helps developers create cloud-native, microservices-based applications with ease, making it an excellent choice for modern Java microservices development.
There are two main styles of building applications with Helidon:
- Helidon SE: A lightweight, reactive, functional, and minimalistic framework for microservices.
- Helidon MP: A more feature-rich framework that is compatible with MicroProfile, offering more structure and tools for building microservices in a standard, opinionated way.
Helidon is designed for cloud-native environments such as Kubernetes, Docker, and microservices architectures.
1. Key Features of Helidon
1.1. Reactive and Imperative Models
- Helidon SE is based on reactive programming and allows you to write non-blocking, asynchronous applications.
- Helidon MP (MicroProfile) builds on the MicroProfile specification and supports traditional imperative programming, but still provides reactive programming support for asynchronous tasks.
1.2. MicroProfile Integration
- Helidon MP implements the MicroProfile specification, a collection of Java APIs aimed at building microservices. This includes features like fault tolerance, metrics, JWT authentication, health checks, and more.
- MicroProfile enables interoperability between Java microservices across various frameworks, ensuring that your application is compliant with the industry standards for building cloud-native microservices.
1.3. Cloud-Native and Kubernetes-Friendly
- Helidon is designed to be cloud-native and integrates seamlessly with Kubernetes, Docker, and other cloud platforms. It supports auto-scaling, service discovery, and distributed tracing.
- The Helidon MP edition also supports health checks, metrics, and configurable logging, making it a great fit for microservices in Kubernetes.
1.4. Fast and Lightweight
- Helidon is lightweight, with small memory footprint and fast startup times. This makes it ideal for cloud-native deployments, where efficiency and performance are critical.
- It provides minimal overhead for handling HTTP requests and allows you to focus on the business logic while leveraging microservices tools out of the box.
1.5. Built-In Support for RESTful Services
- Helidon supports RESTful APIs and is built for building high-performance web services using HTTP, making it easy to expose your microservices to the outside world.
- It integrates well with JAX-RS (Java API for RESTful Web Services) for creating RESTful endpoints and supports JSON, XML, and other formats for communication.
2. Getting Started with Helidon
To get started with Helidon, you need to choose between Helidon SE or Helidon MP, depending on your needs. Here’s an overview of how to get started with both.
2.1. Using Helidon SE (Reactive)
Helidon SE is a reactive framework for building microservices. It allows you to build lightweight services that use non-blocking I/O.
Step 1: Add Dependencies
To use Helidon SE, you need to include the necessary dependencies in your Maven pom.xml
file:
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-se</artifactId>
<version>2.4.0</version>
</dependency>
Step 2: Create a Simple Microservice
A simple Helidon SE microservice can be created by setting up a Main class with a routing definition.
import io.helidon.common.reactive.Single;
import io.helidon.webserver.Routing;
import io.helidon.webserver.WebServer;
public class Main {
public static void main(String[] args) {
WebServer server = WebServer.create(Routing.builder()
.get("/", (req, res) -> res.send("Hello, Helidon!"))
.build());
server.start()
.thenAccept(webServer -> {
System.out.println("Server started at: http://localhost:" + webServer.port());
});
}
}
- The WebServer is created, and the route
/
is defined to respond with “Hello, Helidon!”. - This simple code demonstrates how easy it is to create a reactive microservice using Helidon SE.
Step 3: Run the Microservice
Run the Main class and navigate to http://localhost:8080/
to see the message Hello, Helidon!
being returned from the microservice.
2.2. Using Helidon MP (MicroProfile)
Helidon MP is for developers who want to use a MicroProfile-compliant framework for building Java microservices. It provides a more structured, opinionated approach with tools like RESTful endpoints, health checks, metrics, fault tolerance, etc.
Step 1: Add Dependencies
For Helidon MP, add the following dependencies to the pom.xml
file:
<dependency>
<groupId>io.helidon.microprofile</groupId>
<artifactId>helidon-microprofile</artifactId>
<version>2.4.0</version>
</dependency>
Step 2: Create a RESTful Endpoint
Helidon MP leverages JAX-RS to define RESTful endpoints. Here is a simple Helidon MP example with a REST endpoint:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/hello")
public class HelloResource {
@GET
public String sayHello() {
return "Hello, Helidon MP!";
}
}
- This defines a REST endpoint that listens for
GET
requests on/hello
and returns a message.
Step 3: Deploying and Running the Microservice
You can run the Helidon MP microservice using a Java EE-compatible server, like WildFly, or run it as a standalone application using Helidon‘s own embedded server.
To run it in standalone mode:
import io.helidon.microprofile.server.Server;
public class Main {
public static void main(String[] args) {
Server.create().start();
}
}
When the application runs, visit http://localhost:8080/hello
to see the message Hello, Helidon MP!
.
3. Advantages of Using Helidon for Microservices
- Lightweight and Fast: Helidon is designed to be minimalistic and highly efficient, ensuring that microservices can start quickly and consume fewer resources.
- Reactive and Imperative Programming: Helidon supports both reactive (Helidon SE) and imperative (Helidon MP) programming models, so you can choose the best approach for your microservice architecture.
- MicroProfile Compliant: Helidon MP fully supports the MicroProfile specification, providing a set of standards and tools for building cloud-native microservices, including features like fault tolerance, health checks, metrics, and JWT authentication.
- Cloud-Native: Helidon is built for cloud-native environments, making it easy to deploy in Kubernetes, Docker, and other cloud platforms.
- High-Performance: It is built for performance and scalability, with low memory consumption and fast response times.
- Integration with Modern Tools: Helidon integrates with modern tools for building and managing microservices, such as service discovery, distributed tracing, and prometheus for monitoring.
4. Use Cases for Helidon Microservices
Helidon is ideal for building cloud-native microservices that require high-performance and low-latency response times. Some common use cases include:
- Real-time applications: Applications where low latency and high throughput are essential.
- Microservices architecture: Building distributed systems with multiple microservices that need to be lightweight and fast.
- API gateways: Exposing APIs for clients while managing routing and service discovery.
- IoT applications: Handling large volumes of concurrent requests from IoT devices.
- Event-driven applications: Using reactive programming to handle high concurrency efficiently.