Class GrpcClient
- java.lang.Object
-
- io.vertx.reactivex.grpc.client.GrpcClient
-
public class GrpcClient extends Object
A gRPC client for Vert.x Unlike traditional gRPC clients, this client does not rely on a generated RPC interface to interact with the service. Instead, you can interact with the service with a request/response interfaces and gRPC messages, very much like a traditional client. The client exposes 2 levels of API- a Protobuf message
#request(SocketAddress) API
:GrpcClientRequest
/GrpcClientResponse
with Protobuf messages to call any gRPC service in a generic way - a gRPC message
request(io.vertx.reactivex.core.net.SocketAddress)
:GrpcClientRequest
/GrpcClientRequest
with gRPC messages to call a given method of a gRPC service
original
non RX-ified interface using Vert.x codegen. - a Protobuf message
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<GrpcClient>
__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description GrpcClient(GrpcClient delegate)
GrpcClient(Object delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <Req,Resp,T>
Future<T>call(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, io.reactivex.functions.Function<GrpcClientResponse<Req,Resp>,io.reactivex.Single<T>> resultFn)
Call theservice
gRPC service hosted byserver
.<Req,Resp,T>
Future<T>call(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
Call theservice
gRPC service hosted byserver
.static GrpcClient
client(Vertx vertx)
Create a new clientstatic GrpcClient
client(Vertx vertx, HttpClientOptions options)
Create a new clientFuture<Void>
close()
Close this client.boolean
equals(Object o)
GrpcClient
getDelegate()
int
hashCode()
static GrpcClient
newInstance(GrpcClient arg)
Future<GrpcClientRequest<Buffer,Buffer>>
request(SocketAddress server)
Connect to the remoteserver
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 remoteserver
and create a request for givenmethod
of a hosted gRPC service.<Req,Resp,T>
io.reactivex.Single<T>rxCall(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, io.reactivex.functions.Function<GrpcClientResponse<Req,Resp>,io.reactivex.Single<T>> resultFn)
Call theservice
gRPC service hosted byserver
.<Req,Resp,T>
io.reactivex.Single<T>rxCall(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, Function<GrpcClientResponse<Req,Resp>,Future<T>> resultFn)
Call theservice
gRPC service hosted byserver
.io.reactivex.Completable
rxClose()
Close this client.io.reactivex.Single<GrpcClientRequest<Buffer,Buffer>>
rxRequest(SocketAddress server)
Connect to the remoteserver
and create a request for any hosted gRPC service.<Req,Resp>
io.reactivex.Single<GrpcClientRequest<Req,Resp>>rxRequest(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service)
Connect to the remoteserver
and create a request for givenmethod
of a hosted gRPC service.String
toString()
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<GrpcClient> __TYPE_ARG
-
-
Constructor Detail
-
GrpcClient
public GrpcClient(GrpcClient delegate)
-
GrpcClient
public GrpcClient(Object delegate)
-
-
Method Detail
-
getDelegate
public GrpcClient getDelegate()
-
client
public static GrpcClient client(Vertx vertx)
Create a new client- Parameters:
vertx
- the vertx instance- Returns:
- the created client
-
client
public static GrpcClient client(Vertx vertx, HttpClientOptions options)
Create a new client- Parameters:
vertx
- the vertx instanceoptions
- the client options- Returns:
- the created client
-
request
public Future<GrpcClientRequest<Buffer,Buffer>> request(SocketAddress server)
Connect to the remoteserver
and create a request for any hosted gRPC service.- Parameters:
server
- the server hosting the service- Returns:
- a future request
-
rxRequest
public io.reactivex.Single<GrpcClientRequest<Buffer,Buffer>> rxRequest(SocketAddress server)
Connect to the remoteserver
and create a request for any hosted gRPC service.- Parameters:
server
- the server hosting the service- Returns:
- a future request
-
rxClose
public io.reactivex.Completable rxClose()
Close this client.- Returns:
-
request
public <Req,Resp> Future<GrpcClientRequest<Req,Resp>> request(SocketAddress server, io.grpc.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
-
rxRequest
public <Req,Resp> io.reactivex.Single<GrpcClientRequest<Req,Resp>> rxRequest(SocketAddress server, io.grpc.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
-
call
public <Req,Resp,T> Future<T> call(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, 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
fut = client.call(..., req -> req.send(item), resp -> resp.last()); Future
fut = client.call(..., req -> req.send(stream), resp -> resp.pipeTo(anotherService)); Future
- > 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
-
rxCall
public <Req,Resp,T> io.reactivex.Single<T> rxCall(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, 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
fut = client.call(..., req -> req.send(item), resp -> resp.last()); Future
fut = client.call(..., req -> req.send(stream), resp -> resp.pipeTo(anotherService)); Future
- > 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
public <Req,Resp,T> Future<T> call(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, io.reactivex.functions.Function<GrpcClientResponse<Req,Resp>,io.reactivex.Single<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
fut = client.call(..., req -> req.send(item), resp -> resp.last()); Future
fut = client.call(..., req -> req.send(stream), resp -> resp.pipeTo(anotherService)); Future
- > 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
-
rxCall
public <Req,Resp,T> io.reactivex.Single<T> rxCall(SocketAddress server, io.grpc.MethodDescriptor<Req,Resp> service, Handler<GrpcClientRequest<Req,Resp>> requestHandler, io.reactivex.functions.Function<GrpcClientResponse<Req,Resp>,io.reactivex.Single<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
fut = client.call(..., req -> req.send(item), resp -> resp.last()); Future
fut = client.call(..., req -> req.send(stream), resp -> resp.pipeTo(anotherService)); Future
- > 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
-
newInstance
public static GrpcClient newInstance(GrpcClient arg)
-
-