Module io.inverno.mod.grpc.client


module io.inverno.mod.grpc.client

The Inverno framework gRPC client module provides a gRPC client.

It defines the following sockets:

configuration
the gRPC client module configuration
netService (required)
the Net service providing the ByteBuf allocator
messageCompressors
custom gRPC message compressors

It exposes the following beans:

configuration
the gRPC client module configuration
grpcClient
the gRPC client

A remote gRPC service method can be called by using an HTTP/2 client and transforming the client HTTP exchange into a client gRPC exchange as follows:


 HttpClient httpClient = ... 
 h2Endpoint = httpClient.endpoint("localhost", 8080)
     .configuration(HttpClientConfigurationLoader.load(conf -> conf.http_protocol_versions(Set.of(HttpVersion.HTTP_2_0))))
     .build();
 
 HelloReply reply = h2Endpoint.exchange()
     .map(exchange -> (GrpcExchange.Unary<ExchangeContext, HelloRequest, HelloReply>)grpcClient.unary(
         exchange,
         GrpcServiceName.of("helloworld", "Greeter"), "SayHello",
         HelloRequest.getDefaultInstance(), HelloReply.getDefaultInstance()
     ))
     .flatMap(grpcExchange -> {
         grpcExchange.request().value(
             HelloRequest.newBuilder()
                 .setName("Bob")
                 .build()
         );
         return grpcExchange.response();
     })
     .flatMap(GrpcResponse.Unary::value)
     .block(); 
 

gRPC is only supported on top of the HTTP/2 protocol, the behaviour of an application using an HTTP/1.x client is undetermined.

It is recommended to rely on a protoc plugin for generating a proper gRPC client stub from Protocol buffer definitions.

Since:
1.9
Author:
Jeremy Kuhn