Package io.vertx.grpcio.client
Interface GrpcIoClient
-
- All Superinterfaces:
GrpcClient
public interface GrpcIoClient extends GrpcClient
A gRPC client for Vert.x This server extends theGrpcClient
to encode/decode messages in protobuf format usingMethodDescriptor
. This client exposes 2 levels of API- a Protobuf message
API
:GrpcClientRequest
/GrpcClientResponse
with Protobuf messages to call any gRPC service in a generic way - a gRPC message
request(Address, MethodDescriptor)
:GrpcClientRequest
/GrpcClientRequest
with gRPC messages to call a given method of a gRPC service
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static GrpcClientBuilder<GrpcIoClient>
builder(Vertx vertx)
Provide a builder forGrpcClient
, it can be used to configure advanced client settings like a load balancer or an address resolver.default <Req,Resp,T>
Future<T>call(MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, java.util.function.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, java.util.function.Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
Call theservice
gRPC service hosted byserver
.static GrpcIoClient
client(Vertx vertx)
Create a client.static GrpcIoClient
client(Vertx vertx, HttpClient client)
Create a client wrapping an existingHttpClient
.static GrpcIoClient
client(Vertx vertx, HttpClientOptions options)
Create a client with the specifiedoptions
.static GrpcIoClient
client(Vertx vertx, GrpcClientOptions options)
Create a client.static GrpcIoClient
client(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 remoteserver
and create a request for givenmethod
of a hosted gRPC service.
-
-
-
Method Detail
-
builder
static GrpcClientBuilder<GrpcIoClient> builder(Vertx vertx)
Description copied from interface:GrpcClient
Provide a builder forGrpcClient
, it can be used to configure advanced client settings like a load balancer or an address resolver.Example usage:
GrpcClient client = GrpcClient.builder(vertx).with(options)...build()
-
client
static GrpcIoClient client(Vertx vertx)
Create a client.- Parameters:
vertx
- the vertx instance- Returns:
- the created client
-
client
static GrpcIoClient client(Vertx vertx, GrpcClientOptions options)
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
static GrpcIoClient client(Vertx vertx, HttpClientOptions options)
Create a client with the specifiedoptions
.- Parameters:
vertx
- the vertx instanceoptions
- the http client options- Returns:
- the created client
-
client
static GrpcIoClient client(Vertx vertx, HttpClient 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 remoteserver
and create a request for givenmethod
of a hosted gRPC service.- Parameters:
server
- the server hosting the serviceservice
- the service to be called- Returns:
- a future request
-
request
<Req,Resp> Future<GrpcClientRequest<Req,Resp>> request(MethodDescriptor<Req,Resp> service)
Likerequest(Address, MethodDescriptor)
with the default remote server.
-
call
default <Req,Resp,T> Future<T> call(Address server, MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, java.util.function.Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
Call theservice
gRPC service hosted byserver
.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()));
- 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,T> Future<T> call(MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, java.util.function.Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
Likecall(Address, MethodDescriptor, Handler, Function)
with the default remote server.
-
-