public interface GrpcClient
API
: GrpcClientRequest
/GrpcClientResponse
with Protobuf messages to call any gRPC service in a generic wayrequest(SocketAddress, MethodDescriptor)
: GrpcClientRequest
/GrpcClientRequest
with gRPC messages to call a given method of a gRPC serviceModifier and Type | Method and Description |
---|---|
default <Req,Resp,T> |
call(SocketAddress server,
io.grpc.MethodDescriptor<Req,Resp> service,
Handler<GrpcClientRequest<Req,Resp>> requestHandler,
java.util.function.Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
Call the
service gRPC service hosted by server . |
static GrpcClient |
client(Vertx vertx)
Create a new client
|
static GrpcClient |
client(Vertx vertx,
HttpClientOptions options)
Create a new client
|
Future<Void> |
close()
Close this client.
|
Future<GrpcClientRequest<Buffer,Buffer>> |
request(SocketAddress server)
Connect to the remote
server and create a request for any hosted gRPC service. |
<Req,Resp> Future<GrpcClientRequest<Req,Resp>> |
request(SocketAddress server,
io.grpc.MethodDescriptor<Req,Resp> service)
Connect to the remote
server and create a request for given method of a hosted gRPC service. |
static GrpcClient client(Vertx vertx)
vertx
- the vertx instancestatic GrpcClient client(Vertx vertx, HttpClientOptions options)
vertx
- the vertx instanceoptions
- the client optionsFuture<GrpcClientRequest<Buffer,Buffer>> request(SocketAddress server)
server
and create a request for any hosted gRPC service.server
- the server hosting the service<Req,Resp> Future<GrpcClientRequest<Req,Resp>> request(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service)
server
and create a request for given method
of a hosted gRPC service.server
- the server hosting the serviceservice
- the service to be calleddefault <Req,Resp,T> Future<T> call(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, java.util.function.Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
service
gRPC service hosted by server
.
The requestHandler
is called to send the request, e.g. req -> req.send(item)
The responseFunction
extracts 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()));
server
- the server hosting the serviceservice
- the service to callrequestHandler
- the handler called to send the requestresultFn
- the function applied to extract the result.Copyright © 2023 Eclipse. All rights reserved.