Interface GrpcIoClient
- All Superinterfaces:
GrpcClient
A gRPC client for Vert.x
This server extends the
GrpcClient to encode/decode messages in protobuf format using MethodDescriptor.
This client exposes 2 levels of API
- a Protobuf message
API:GrpcClientRequest/GrpcClientResponsewith Protobuf messages to call any gRPC service in a generic way - a gRPC message
request(Address, MethodDescriptor):GrpcClientRequest/GrpcClientRequestwith gRPC messages to call a given method of a gRPC service
-
Method Summary
Modifier and TypeMethodDescriptionstatic GrpcClientBuilder<GrpcIoClient> default <Req,Resp, T>
Future<T> call(MethodDescriptor<Req, Resp> service, Handler<GrpcClientRequest<Req, Resp>> requestHandler, Function<GrpcClientResponse<Req, Resp>, Future<T>> resultFn) Likecall(Address, MethodDescriptor, Handler, Function)with the default remote server.default <Req,Resp, T>
Future<T> call(Address server, MethodDescriptor<Req, Resp> service, Handler<GrpcClientRequest<Req, Resp>> requestHandler, Function<GrpcClientResponse<Req, Resp>, Future<T>> resultFn) Call theservicegRPC service hosted byserver.static GrpcIoClientCreate a client.static GrpcIoClientclient(Vertx vertx, HttpClient client) Create a client wrapping an existingHttpClient.static GrpcIoClientclient(Vertx vertx, HttpClientOptions options) Create a client with the specifiedoptions.static GrpcIoClientclient(Vertx vertx, GrpcClientOptions options) Create a client.static GrpcIoClientclient(Vertx vertx, GrpcClientOptions grpcOptions, HttpClientOptions httpOptions) Create a client with the specifiedoptions.<Req,Resp> Future <GrpcClientRequest<Req, Resp>> request(MethodDescriptor<Req, Resp> service) Likerequest(Address, MethodDescriptor)with the default remote server.<Req,Resp> Future <GrpcClientRequest<Req, Resp>> request(Address server, MethodDescriptor<Req, Resp> service) Connect to the remoteserverand create a request for givenmethodof a hosted gRPC service.
-
Method Details
-
builder
-
client
Create a client.- Parameters:
vertx- the vertx instance- Returns:
- the created client
-
client
Create a client.- Parameters:
vertx- the vertx instance- Returns:
- the created client
-
client
static GrpcIoClient client(Vertx vertx, GrpcClientOptions grpcOptions, HttpClientOptions httpOptions) Create a client with the specifiedoptions.- Parameters:
vertx- the vertx instancegrpcOptions- the http client optionshttpOptions- the http client options- Returns:
- the created client
-
client
Create a client with the specifiedoptions.- Parameters:
vertx- the vertx instanceoptions- the http client options- Returns:
- the created client
-
client
Create a client wrapping an existingHttpClient.- Parameters:
vertx- the vertx instanceclient- the http client instance- Returns:
- the created client
-
request
<Req,Resp> Future<GrpcClientRequest<Req,Resp>> request(Address server, MethodDescriptor<Req, Resp> service) Connect to the remoteserverand create a request for givenmethodof a hosted gRPC service.- Parameters:
server- the server hosting the serviceservice- the service to be called- Returns:
- a future request
-
request
Likerequest(Address, MethodDescriptor)with the default remote server. -
call
default <Req,Resp, Future<T> callT> (Address server, MethodDescriptor<Req, Resp> service, Handler<GrpcClientRequest<Req, Resp>> requestHandler, Function<GrpcClientResponse<Req, Resp>, Future<T>> resultFn) Call theservicegRPC service hosted byserver.The
requestHandleris called to send the request, e.g.req -> req.send(item)The
responseFunctionextracts the result, e.g.resp -> resp.last()It can be used in various ways:
Future<Resp> fut = client.call(..., req -> req.send(item), resp -> resp.last());Future<Void> fut = client.call(..., req -> req.send(stream), resp -> resp.pipeTo(anotherService));Future<List<Resp>> fut = client.call(..., req -> req.send(stream), resp -> resp.collecting(Collectors.toList()));
- Parameters:
server- the server hosting the serviceservice- the service to callrequestHandler- the handler called to send the requestresultFn- the function applied to extract the result.- Returns:
- a future of the result
-
call
default <Req,Resp, Future<T> callT> (MethodDescriptor<Req, Resp> service, Handler<GrpcClientRequest<Req, Resp>> requestHandler, Function<GrpcClientResponse<Req, Resp>, Future<T>> resultFn) Likecall(Address, MethodDescriptor, Handler, Function)with the default remote server.
-