Search in sources :

Example 11 with GrpcServerConfiguration

use of io.helidon.grpc.server.GrpcServerConfiguration 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();
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) TreeMapService(services.TreeMapService) StringService(services.StringService) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 12 with GrpcServerConfiguration

use of io.helidon.grpc.server.GrpcServerConfiguration 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);
}
Also used : GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) TreeMapService(services.TreeMapService) Channel(io.grpc.Channel) StringService(services.StringService) GrpcRouting(io.helidon.grpc.server.GrpcRouting) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 13 with GrpcServerConfiguration

use of io.helidon.grpc.server.GrpcServerConfiguration 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;
    });
}
Also used : StringService(io.helidon.grpc.examples.common.StringService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) WebServer(io.helidon.webserver.WebServer) GrpcServer(io.helidon.grpc.server.GrpcServer) GreetService(io.helidon.grpc.examples.common.GreetService) MetricsSupport(io.helidon.metrics.MetricsSupport) LogConfig(io.helidon.common.LogConfig) Routing(io.helidon.webserver.Routing) GrpcMetrics(io.helidon.grpc.metrics.GrpcMetrics) GrpcRouting(io.helidon.grpc.server.GrpcRouting) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) LogConfig(io.helidon.common.LogConfig) GreetService(io.helidon.grpc.examples.common.GreetService) Routing(io.helidon.webserver.Routing) GrpcRouting(io.helidon.grpc.server.GrpcRouting) StringService(io.helidon.grpc.examples.common.StringService) GrpcServer(io.helidon.grpc.server.GrpcServer) GrpcRouting(io.helidon.grpc.server.GrpcRouting)

Example 14 with GrpcServerConfiguration

use of io.helidon.grpc.server.GrpcServerConfiguration in project helidon by oracle.

the class ZipkinExampleMain method main.

/**
 * Program entry point.
 *
 * @param args the program command line arguments
 * @throws Exception if there is a program error
 */
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();
    Tracer tracer = TracerBuilder.create(config.get("tracing")).build();
    GrpcTracingConfig tracingConfig = GrpcTracingConfig.builder().withStreaming().withVerbosity().withTracedAttributes(ServerRequestAttribute.CALL_ATTRIBUTES, ServerRequestAttribute.HEADERS, ServerRequestAttribute.METHOD_NAME).build();
    // Get gRPC server config from the "grpc" section of application.yaml
    GrpcServerConfiguration serverConfig = GrpcServerConfiguration.builder(config.get("grpc")).tracer(tracer).tracingConfig(tracingConfig).build();
    GrpcServer grpcServer = GrpcServer.create(serverConfig, createRouting(config));
    // 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;
    });
}
Also used : GrpcTracingConfig(io.helidon.grpc.server.GrpcTracingConfig) TracerBuilder(io.helidon.tracing.TracerBuilder) StringService(io.helidon.grpc.examples.common.StringService) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Tracer(io.opentracing.Tracer) Config(io.helidon.config.Config) GrpcServer(io.helidon.grpc.server.GrpcServer) GrpcTracingConfig(io.helidon.grpc.server.GrpcTracingConfig) GreetService(io.helidon.grpc.examples.common.GreetService) ServerRequestAttribute(io.helidon.grpc.server.ServerRequestAttribute) LogConfig(io.helidon.common.LogConfig) GrpcRouting(io.helidon.grpc.server.GrpcRouting) GrpcServerConfiguration(io.helidon.grpc.server.GrpcServerConfiguration) Config(io.helidon.config.Config) GrpcTracingConfig(io.helidon.grpc.server.GrpcTracingConfig) LogConfig(io.helidon.common.LogConfig) Tracer(io.opentracing.Tracer) GrpcServer(io.helidon.grpc.server.GrpcServer)

Aggregations

GrpcRouting (io.helidon.grpc.server.GrpcRouting)14 GrpcServerConfiguration (io.helidon.grpc.server.GrpcServerConfiguration)14 LogConfig (io.helidon.common.LogConfig)10 Config (io.helidon.config.Config)8 GrpcServer (io.helidon.grpc.server.GrpcServer)8 BeforeAll (org.junit.jupiter.api.BeforeAll)7 StringService (io.helidon.grpc.examples.common.StringService)6 Channel (io.grpc.Channel)5 Security (io.helidon.security.Security)5 GreetService (io.helidon.grpc.examples.common.GreetService)4 ServiceDescriptor (io.helidon.grpc.server.ServiceDescriptor)4 Routing (io.helidon.webserver.Routing)4 StringService (services.StringService)4 GrpcSecurity (io.helidon.security.integration.grpc.GrpcSecurity)3 WebServer (io.helidon.webserver.WebServer)3 EchoService (services.EchoService)3 MetricsSupport (io.helidon.metrics.MetricsSupport)2 TreeMapService (services.TreeMapService)2 ManagedChannelBuilder (io.grpc.ManagedChannelBuilder)1 MediaType (io.helidon.common.http.MediaType)1