use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class PojoServiceClientIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
GrpcRouting routing = GrpcRouting.builder().register(new TreeMapService()).register(new StringService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
channel = ManagedChannelBuilder.forAddress("localhost", grpcServer.port()).usePlaintext().build();
}
use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class ProtoGrpcServiceClientIT method startServer.
@BeforeAll
public static void startServer() throws Exception {
LogConfig.configureRuntime();
GrpcRouting routing = GrpcRouting.builder().intercept(headerCheckingInterceptor).register(new TreeMapService()).register(new StringService()).build();
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder().port(0).build();
grpcServer = GrpcServer.create(serverConfig, routing).start().toCompletableFuture().get(10, TimeUnit.SECONDS);
ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).intercept(mediumPriorityInterceptor).intercept("Upper", highPriorityInterceptor).intercept("Lower", lowPriorityInterceptor).callCredentials(serviceCred).callCredentials("Lower", lowerMethodCred).callCredentials("Join", joinMethodCred).build();
Channel channel = ManagedChannelBuilder.forAddress("localhost", grpcServer.port()).usePlaintext().build();
grpcClient = GrpcServiceClient.create(channel, descriptor);
}
use of io.helidon.grpc.server.GrpcRouting in project helidon by oracle.
the class Server method main.
/**
* The main program entry point.
*
* @param args the program arguments
*
* @throws Exception if an error occurs
*/
public static void main(String[] args) throws Exception {
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
// load logging configuration
LogConfig.configureRuntime();
// Get gRPC server config from the "grpc" section of application.yaml
GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder(config.get("grpc")).build();
GrpcRouting grpcRouting = GrpcRouting.builder().intercept(// global metrics - all service methods counted
GrpcMetrics.counted()).register(// GreetService uses global metrics so all methods are counted
new GreetService(config)).register(new StringService(), rules -> {
// service level metrics - StringService overrides global so that its methods are timed
rules.intercept(GrpcMetrics.timed()).intercept("Upper", GrpcMetrics.histogram());
}).build();
GrpcServer grpcServer = GrpcServer.create(serverConfig, grpcRouting);
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
grpcServer.start().thenAccept(s -> {
System.out.println("gRPC server is UP! http://localhost:" + s.port());
s.whenShutdown().thenRun(() -> System.out.println("gRPC server is DOWN. Good bye!"));
}).exceptionally(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
return null;
});
// start web server with the metrics endpoints
Routing routing = Routing.builder().register(MetricsSupport.create()).build();
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;
});
}
Aggregations