userver: ugrpc::client::GenericClient Class Reference
Loading...
Searching...
No Matches
ugrpc::client::GenericClient Class Referencefinal

#include <userver/ugrpc/client/generic.hpp>

Detailed Description

Allows to talk to gRPC services (generic and normal) using dynamic method names.

Created using ClientFactory::MakeClient.

call_name must be in the format full.path.to.TheService/MethodName. Note that unlike in base grpc++, there must be no initial / character.

The API is mainly intended for proxies, where the request-response body is passed unchanged, with settings taken solely from the RPC metadata. In cases where the code needs to operate on the actual messages, serialization of requests and responses is left as an excercise to the user.

Middlewares are customizable and are applied as usual, except that no message hooks are called, meaning that there won't be any logs of messages from the default middleware.

There are no per-call-name metrics by default, for details see GenericOptions::metrics_call_name.

Example GenericClient usage with known message types

const auto client = client_factory.MakeClient<ugrpc::client::GenericClient>();
constexpr std::string_view call_name =
"sample.ugrpc.UnitTestService/SayHello";
sample::ugrpc::GreetingRequest request;
request.set_name("generic");
auto rpc = client.UnaryCall(call_name, ugrpc::SerializeToByteBuffer(request));
auto response_bytes = rpc.Finish();
sample::ugrpc::GreetingResponse response;
if (!ugrpc::ParseFromByteBuffer(std::move(response_bytes), response)) {
throw ugrpc::client::RpcError(rpc.GetCallName(),
"Failed to parse response");
}
return response;

For a more complete sample, see grpc_generic_api.

Definition at line 65 of file generic.hpp.

Public Member Functions

 GenericClient (GenericClient &&) noexcept=default
 
GenericClientoperator= (GenericClient &&) noexcept=delete
 
client::UnaryCall< grpc::ByteBuffer > UnaryCall (std::string_view call_name, const grpc::ByteBuffer &request, std::unique_ptr< grpc::ClientContext > context=std::make_unique< grpc::ClientContext >(), const GenericOptions &options={}) const
 Initiate a single request -> single response RPC with the given name.
 

The documentation for this class was generated from the following file: