userver: userver/ugrpc/client/generic_client.hpp Source File
Loading...
Searching...
No Matches
generic_client.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/client/generic_client.hpp
4/// @brief @copybrief ugrpc::client::GenericClient
5
6#include <optional>
7#include <string_view>
8
9#include <grpcpp/support/byte_buffer.h>
10
11#include <userver/utils/box.hpp>
12
13#include <userver/ugrpc/client/call_options.hpp>
14#include <userver/ugrpc/client/generic_options.hpp>
15#include <userver/ugrpc/client/impl/fwd.hpp>
16#include <userver/ugrpc/client/response_future.hpp>
17#include <userver/ugrpc/impl/static_service_metadata.hpp>
18
19USERVER_NAMESPACE_BEGIN
20
21namespace ugrpc::client {
22
23/// @ingroup userver_clients
24///
25/// @brief Allows to talk to gRPC services (generic and normal) using dynamic
26/// method names.
27///
28/// Created using @ref ugrpc::client::ClientFactory::MakeClient.
29///
30/// `call_name` must be in the format `full.path.to.TheService/MethodName`.
31/// Note that unlike in base grpc++, there must be no initial `/` character.
32///
33/// The API is mainly intended for proxies, where the request-response body is
34/// passed unchanged, with settings taken solely from the RPC metadata.
35/// In cases where the code needs to operate on the actual messages,
36/// serialization of requests and responses is left as an exercise to the user.
37///
38/// Middlewares are customizable and are applied as usual, except that no
39/// message hooks are called, meaning that there won't be any logs of messages
40/// from the default middleware.
41///
42/// There are no per-call-name metrics by default,
43/// for details see @ref GenericOptions::metrics_call_name.
44///
45/// @warning Retry limiters (configured via `retry-throttler` in
46/// @ref ugrpc::client::CommonComponent) are not supported for GenericClient.
47/// The setting is ignored, and retry limiting will not be applied to generic
48/// calls. For retry limiting functionality, use regular typed gRPC clients.
49///
50/// ## Example GenericClient usage with known message types
51///
52/// @snippet grpc/tests/generic_client_test.cpp sample
53///
54/// For a more complete sample, see @ref grpc_generic_api.
55class GenericClient final {
56public:
57 GenericClient(GenericClient&&) noexcept;
58 GenericClient& operator=(GenericClient&&) noexcept;
59
60 ~GenericClient();
61
62 /// Initiate a `single request -> single response` RPC with the given name.
63 ResponseFuture<grpc::ByteBuffer> AsyncUnaryCall(
64 std::string_view call_name,
65 const grpc::ByteBuffer& request,
66 CallOptions call_options = {},
67 GenericOptions generic_options = {}
68 ) const;
69
70 /// Initiate a `single request -> single response` RPC with the given name.
71 grpc::ByteBuffer UnaryCall(
72 std::string_view call_name,
73 const grpc::ByteBuffer& request,
74 CallOptions call_options = {},
75 GenericOptions generic_options = {}
76 ) const;
77
78 /// @cond
79 // For internal use only.
80 explicit GenericClient(impl::ClientInternals&&);
81
82 // For internal use only.
83 static std::optional<ugrpc::impl::StaticServiceMetadata> GetMetadata(utils::impl::InternalTag) {
84 return std::nullopt;
85 }
86 /// @endcond
87
88private:
89 friend class impl::ClientDataAccessor;
90
91 utils::Box<impl::ClientData> client_data_;
92};
93
94} // namespace ugrpc::client
95
96USERVER_NAMESPACE_END