Helidon brings MicroProfile 2.2+ support

We are pleased to announce the 1.2.0 release of Helidon. This release adds support for MicroProfile 2.2 and includes additional bug and performance fixes. Let’s take a closer look at what’s in the release.

MicroProfile

MicroProfile is now a de-facto standard for Java cloud-native APIs. One of the main goals of project Helidon is to deliver support for the latest MicroProfile APIs. The Helidon MicroProfile implementation is called Helidon MP and along with the reactive, non-blocking framework called Helidon SE it builds the core of Helidon.

We have been adding support for newer MicroProfile specifications one by one during the last few releases. The 1.2.0 release brings MicroProfile REST Client 1.2.1 and Open Tracing 1.3. With these pieces in place we now have full MicroProfile 2.2 support.

The full list of supported MicroProfile and Java EE APIs is listed on this image:

As you see, we added support for two more Java EE APIs: JPA (Persistence) and JTA (Transaction). It’s in early access at the moment. You should consider it as a preview. We are still working on it and the implementation and configuration is subject to change.

Here are some examples of using new APIs added in Helidon 1.2.0.

MicroProfile REST Client sample

Register a rest client interface (can be the same one that is implemented by the JAX-RS resource). Note that the URI can be overridden using configuration.

@RegisterRestClient(baseUri = "http://localhost:8081/greet")
public interface GreetResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    JsonObject getDefaultMessage();
    
    @Path("/{name}")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    JsonObject getMessage(@PathParam("name") String name);
}

Declare the rest client in a class using it (such as a JAX-RS resource in a different microservice):

@Inject
@RestClient
private GreetResource greetService;

And simply use the field to invoke the remote service (this example proxies the request to the remote service):

@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getDefaultMessage() {
    return greetService.getDefaultMessage();
}

Health Check 2.0 sample

Health Check 2.0 has two types of checks (in previous versions a single type existed):

  • Readiness — used by clients (such as Kubernetes readiness check) to check if the service has started and can be used
  • Liveness — used by clients (such as Kubernetes liveness checks) to check if the service is still up and running

Simply annotate an application scoped bean with the appropriate annotation (@Readiness or @Liveness) to create a health check:

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Liveness;

@Liveness
@ApplicationScoped
public class GreetHealthcheck implements HealthCheck {
    private GreetingProvider provider;
  
    @Inject
    public GreetHealthcheck(GreetingProvider provider) 
        this.provider = provider;
    }

    @Override
    public HealthCheckResponse call() {
        String message = provider.getMessage();
        return HealthCheckResponse.named("greeting")
            .state("Hello".equals(message))
            .withData("greeting", message)
            .build();
    }
}

Open Tracing Sample

MP Open Tracing adds a single annotation: @Traced, to add tracing to CDI beans.

Tracing of JAX-RS resources is automated (and can be disabled with the @Traced). Example of the bean used in the Health check example (the method getMessage is traced):

@ApplicationScoped
public class GreetingProvider {
    private final AtomicReference<String> message = new AtomicReference<>();
    
    /**
     * Create a new greeting provider, reading the message 
     * from configuration.
     *
     * @param message greeting to use
     */
    @Inject
    public GreetingProvider(
        @ConfigProperty(name = "app.greeting") String message) {
        this.message.set(message);
    }
    
    @Traced(operationName = "GreetingProvider.getMessage")
    String getMessage() {
        return message.get();
    }
    
    ...
}

Other Enhancements

In addition to MicroProfile 2.2, Helidon 1.2.0 contains a couple other enhancements:

  • HTTP Access Log support for Helidon MP and SE.
  • Early Access: Oracle Universal Connection Pool support: this lets you configure and inject the Oracle UCP JDBC driver as a DataSource in your Helidon MP application.

More to Come

With MicroProfile 2.2 support, Helidon has caught up with most of the other main MicroProfile implementations. We are now pushing Helidon towards MicroProfile 3.0, and we’ve already taken the first steps. That’s why we put a plus after 2.2 in the title. We already have support for Health Check 2.0 (and we’ll support it in a backwards compatible way). That leaves Metrics 2.0 and REST Client 1.3 and we are working hard to deliver it next month.

Stay tuned!

Thanks to Tomas Langer for helping with samples and to Joe Di Pol for great conversational style.

One thought on “Helidon brings MicroProfile 2.2+ support

  1. […] このエントリは以下のエントリをベースにしています。This entry is based on the following one, written by Dmitry Kornilov (Eclipse EE4J PMC member, Jakarta EE contributor, JCP star spec lead, Helidon Project lead, Oracle).https://dmitrykornilov.net/2019/08/08/helidon-brings-microprofile-2-2-support/https://medium.com/oracledevs/helidon-brings-microprofile-2-2-support-93d85bb4223e […]

    Like

Leave a comment