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

Update examples/graphql/basics to use Nima #6854

Merged
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
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