Skip to content

Commit

Permalink
Add healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
smolthing committed Jul 2, 2023
1 parent b4983d3 commit 6f86182
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/backend/starter/HealthCheckManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.backend.starter;

import io.vertx.ext.healthchecks.HealthCheckHandler;
import io.vertx.ext.healthchecks.Status;

public class HealthCheckManager {
public static void configureHealthChecks(HealthCheckHandler healthCheckHandler) {
healthCheckHandler.register("App connection", promise -> {
promise.complete(Status.OK());
});
}
}
23 changes: 17 additions & 6 deletions src/main/java/com/backend/starter/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Promise;
import io.vertx.ext.healthchecks.HealthCheckHandler;
import io.vertx.ext.healthchecks.HealthChecks;
import io.vertx.ext.web.Router;

public class MainVerticle extends AbstractVerticle {

@Override
public void start(Promise<Void> startPromise) throws Exception {
vertx.createHttpServer().requestHandler(req -> {
req.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
}).listen(8888, http -> {
HealthCheckHandler healthCheckHandler = HealthCheckHandler
.createWithHealthChecks(HealthChecks.create(vertx));
HealthCheckManager.configureHealthChecks(healthCheckHandler);

Router router = Router.router(vertx);
router.get("/ping").handler(healthCheckHandler);
router.get("/*").handler(routingContext -> {
routingContext.response()
.putHeader("content-type", "text/plain; charset=utf-8")
.end("Hello smolthing \uD83D\uDCA9.");
});

vertx.createHttpServer().requestHandler(router).listen(8888, http -> {
if (http.succeeded()) {
startPromise.complete();
System.out.println("HTTP server started on port 8888");
System.out.println("HTTP server is running on port 8888");
} else {
startPromise.fail(http.cause());
}
Expand Down

0 comments on commit 6f86182

Please sign in to comment.