Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting of example to Nima and removal of reactive dependencies #6839

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/health/basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@

<dependencies>
<dependency>
<groupId>io.helidon.reactive.health</groupId>
<artifactId>helidon-reactive-health</artifactId>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.health</groupId>
<artifactId>helidon-health-checks</artifactId>
<groupId>io.helidon.nima.observe</groupId>
<artifactId>helidon-nima-observe-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.reactive.webserver</groupId>
<artifactId>helidon-reactive-webserver</artifactId>
<groupId>io.helidon.health</groupId>
<artifactId>helidon-health-checks</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,12 +17,14 @@

import java.time.Duration;

import io.helidon.health.checks.HealthChecks;
import io.helidon.reactive.health.HealthSupport;
import io.helidon.reactive.webserver.Routing;
import io.helidon.reactive.webserver.WebServer;

import org.eclipse.microprofile.health.HealthCheckResponse;
import io.helidon.health.HealthCheckResponse;
import io.helidon.health.HealthCheckType;
import io.helidon.logging.common.LogConfig;
import io.helidon.nima.observe.ObserveFeature;
import io.helidon.nima.observe.health.HealthFeature;
import io.helidon.nima.observe.health.HealthObserveProvider;
import io.helidon.nima.webserver.WebServer;
import io.helidon.nima.webserver.http.HttpRouting;

/**
* Main class of health check integration example.
Expand All @@ -41,33 +43,42 @@ private Main() {
*/
public static void main(String[] args) {
serverStartTime = System.currentTimeMillis();
HealthSupport health = HealthSupport.builder()
.add(HealthChecks.healthChecks())
.addReadiness(() -> HealthCheckResponse.named("exampleHealthCheck")
.up()
.withData("time", System.currentTimeMillis())
.build())
.addStartup(() -> HealthCheckResponse.named("exampleStartCheck")
.status(isStarted())
.withData("time", System.currentTimeMillis())
.build())
.build();

Routing routing = Routing.builder()
.register(health)
.get("/hello", (req, res) -> res.send("Hello World!"))
.build();
// load logging
LogConfig.configureRuntime();

WebServer server = WebServer.builder()
.routing(Main::routing)
.start();

System.out.println("WEB server is up! http://localhost:" + server.port());
}

WebServer ws = WebServer.create(routing);
/**
* Set up HTTP routing.
* This method is used from tests as well.
*
* @param router HTTP routing builder
*/
static void routing(HttpRouting.Builder router) {
ObserveFeature observe = ObserveFeature.builder()
.useSystemServices(true)
.addProvider(HealthObserveProvider.create(HealthFeature.builder()
.useSystemServices(true)
.addCheck(() -> HealthCheckResponse.builder()
.status(HealthCheckResponse.Status.UP)
.detail("time", System.currentTimeMillis())
.build(), HealthCheckType.READINESS)
.addCheck(() -> HealthCheckResponse.builder()
.status(isStarted())
.detail("time", System.currentTimeMillis())
.build(), HealthCheckType.STARTUP)
.build()))
.build();

ws.start()
.thenApply(webServer -> {
String endpoint = "http://localhost:" + webServer.port();
System.out.println("Hello World started on " + endpoint + "/hello");
System.out.println("Health checks available on " + endpoint + "/health");
return null;
});

router.get("/hello", (req, res) -> res.send("Hello World!"))
.addFeature(observe);
}

private static boolean isStarted() {
Expand Down