Module io.inverno.mod.grpc.server


module io.inverno.mod.grpc.server

The Inverno framework gRPC server module provides a gRPC server.

It defines the following sockets:

netService (required)
the Net service providing the ByteBuf allocator
configuration
the gRPC server module configuration
extensionRegistry
the Protocol buffer extension registry
messageCompressors
custom gRPC message compressors

It exposes the following beans:

configuration
the gRPC server module configuration
grpcServer
the gRPC server

A simple gRPC server can be started with an HTTP/2 server by transforming server HTTPexchange handler into a server gRPC exchange handler as follows:


 GrpcServer grpcServer = ...
 NetService netService = ...
 ResourceService resourceService = ...
 		
 Application.with(new Server.Builder(netService, resourceService)
     .setConfiguration(HttpServerConfigurationLoader.load(conf -> conf.server_port(8080).h2_enabled(true)))
     .setController(ServerController.from(
         grpcServer.unary(
             HelloRequest.getDefaultInstance(), 
             HelloReply.getDefaultInstance(), 
             (GrpcExchange.Unary<ExchangeContext, HelloRequest, HelloReply> grpcExchange) -> {
                 grpcExchange.response().value(
                     grpcExchange.request().value().map(request -> HelloReply.newBuilder().setMessage("Hello " + request.getName()).build())
                 );
             }
         )
     ))
 ).run();
 

Note that in above example, all requests sent to the server are processed with the same handler, the io.inverno.mod.web.server is better suited to route requests based on gRPC service and method names. It is recommended to rely on a protoc plugin for generating a proper gRPC Web routes configurer from Protocol buffer definitions.

Since:
1.9
Author:
Jeremy Kuhn