Skip to content

Commit 6277f47

Browse files
aserkesdalexandrov
authored andcommitted
Update examples/graphql/basics to use Nima (helidon-io#6854)
Signed-off-by: aserkes <[email protected]>
1 parent d07d150 commit 6277f47

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

examples/grpc/basics/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
</properties>
4040

4141
<dependencies>
42+
<dependency>
43+
<groupId>io.helidon.nima.webserver</groupId>
44+
<artifactId>helidon-nima-webserver</artifactId>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.helidon.nima.observe</groupId>
48+
<artifactId>helidon-nima-observe-health</artifactId>
49+
</dependency>
4250
<dependency>
4351
<groupId>io.helidon.examples.grpc</groupId>
4452
<artifactId>helidon-examples-grpc-common</artifactId>

examples/grpc/basics/src/main/java/io/helidon/grpc/examples/basics/Server.java

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,11 +23,10 @@
2323
import io.helidon.grpc.server.GrpcRouting;
2424
import io.helidon.grpc.server.GrpcServer;
2525
import io.helidon.grpc.server.GrpcServerConfiguration;
26-
import io.helidon.health.checks.HealthChecks;
2726
import io.helidon.logging.common.LogConfig;
28-
import io.helidon.reactive.health.HealthSupport;
29-
import io.helidon.reactive.webserver.Routing;
30-
import io.helidon.reactive.webserver.WebServer;
27+
import io.helidon.nima.observe.ObserveFeature;
28+
import io.helidon.nima.webserver.WebServer;
29+
import io.helidon.nima.webserver.http.HttpRouting;
3130

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

56-
GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
55+
GrpcServer grpcServer = GrpcServer.create(serverConfig, createGrpcRouting(config));
5756

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

71-
// add support for standard and gRPC health checks
72-
HealthSupport health = HealthSupport.builder()
73-
.add(HealthChecks.healthChecks())
74-
.addLiveness(grpcServer.healthChecks())
75-
.build();
70+
WebServer server = WebServer.builder()
71+
.routing(Server::routing)
72+
.start();
7673

77-
// start web server with health endpoint
78-
Routing routing = Routing.builder()
79-
.register(health)
80-
.build();
74+
System.out.println("WEB server is up! http://localhost:" + server.port());
75+
}
8176

82-
WebServer.create(routing, config.get("webserver"))
83-
.start()
84-
.thenAccept(s -> {
85-
System.out.println("HTTP server is UP! http://localhost:" + s.port());
86-
s.whenShutdown().thenRun(() -> System.out.println("HTTP server is DOWN. Good bye!"));
87-
})
88-
.exceptionally(t -> {
89-
System.err.println("Startup failed: " + t.getMessage());
90-
t.printStackTrace(System.err);
91-
return null;
92-
});
77+
private static void routing(HttpRouting.Builder routing) {
78+
routing.addFeature(ObserveFeature.create());
9379
}
9480

95-
private static GrpcRouting createRouting(Config config) {
81+
private static GrpcRouting createGrpcRouting(Config config) {
9682
GreetService greetService = new GreetService(config);
9783
GreetServiceJava greetServiceJava = new GreetServiceJava(config);
9884

0 commit comments

Comments
 (0)