Skip to content

Commit

Permalink
Update examples/graphql/basics to use Nima (#6854)
Browse files Browse the repository at this point in the history
Signed-off-by: aserkes <andrii.serkes@oracle.com>
  • Loading branch information
aserkes authored May 24, 2023
1 parent 607dbd5 commit 165343d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
8 changes: 8 additions & 0 deletions examples/grpc/basics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.nima.webserver</groupId>
<artifactId>helidon-nima-webserver</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.nima.observe</groupId>
<artifactId>helidon-nima-observe-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.examples.grpc</groupId>
<artifactId>helidon-examples-grpc-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 Oracle and/or its affiliates.
* Copyright (c) 2019, 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 @@ -23,11 +23,10 @@
import io.helidon.grpc.server.GrpcRouting;
import io.helidon.grpc.server.GrpcServer;
import io.helidon.grpc.server.GrpcServerConfiguration;
import io.helidon.health.checks.HealthChecks;
import io.helidon.logging.common.LogConfig;
import io.helidon.reactive.health.HealthSupport;
import io.helidon.reactive.webserver.Routing;
import io.helidon.reactive.webserver.WebServer;
import io.helidon.nima.observe.ObserveFeature;
import io.helidon.nima.webserver.WebServer;
import io.helidon.nima.webserver.http.HttpRouting;

/**
* A basic example of a Helidon gRPC server.
Expand All @@ -53,7 +52,7 @@ public static void main(String[] args) {
GrpcServerConfiguration serverConfig =
GrpcServerConfiguration.builder(config.get("grpc")).build();

GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
GrpcServer grpcServer = GrpcServer.create(serverConfig, createGrpcRouting(config));

// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
Expand All @@ -68,31 +67,18 @@ public static void main(String[] args) {
return null;
});

// add support for standard and gRPC health checks
HealthSupport health = HealthSupport.builder()
.add(HealthChecks.healthChecks())
.addLiveness(grpcServer.healthChecks())
.build();
WebServer server = WebServer.builder()
.routing(Server::routing)
.start();

// start web server with health endpoint
Routing routing = Routing.builder()
.register(health)
.build();
System.out.println("WEB server is up! http://localhost:" + server.port());
}

WebServer.create(routing, config.get("webserver"))
.start()
.thenAccept(s -> {
System.out.println("HTTP server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("HTTP server is DOWN. Good bye!"));
})
.exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
private static void routing(HttpRouting.Builder routing) {
routing.addFeature(ObserveFeature.create());
}

private static GrpcRouting createRouting(Config config) {
private static GrpcRouting createGrpcRouting(Config config) {
GreetService greetService = new GreetService(config);
GreetServiceJava greetServiceJava = new GreetServiceJava(config);

Expand Down

0 comments on commit 165343d

Please sign in to comment.