userver: userver/ugrpc/client/call_options.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
call_options.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/client/call_options.hpp
4/// @brief @copybrief ugrpc::client::CallOptions
5
6#include <chrono>
7#include <string_view>
8#include <utility>
9#include <vector>
10
11#include <grpcpp/client_context.h>
12#include <grpcpp/support/config.h>
13
14#include <userver/utils/move_only_function.hpp>
15
16USERVER_NAMESPACE_BEGIN
17
18namespace ugrpc::client {
19
20namespace impl {
21class CallOptionsAccessor;
22} // namespace impl
23
24/// @brief Options passed to interface calls
26public:
27 /// @{
28 /// Set and get retry attempts. Maximum number of retry attempts, including the original attempt.
29 void SetAttempts(int attempts);
30 int GetAttempts() const;
31 /// @}
32
33 /// @{
34 /// Set and get operation timeout.
35 ///
36 /// In case of retries `timeout` applies to each attempt.
37 /// Maximum time on call may actually be `timeout * attempts + sum(backoff_i)`
38 void SetTimeout(std::chrono::milliseconds timeout);
39 std::chrono::milliseconds GetTimeout() const;
40 /// @}
41
42 /// Add the (\a meta_key, \a meta_value) pair to the metadata associated with a client call.
43 void AddMetadata(std::string_view meta_key, std::string_view meta_value);
44
45 /// @{
46 /// Set custom grpc::ClientContext factory.
47 ///
48 /// 'client_context_factory' may be called zero, once or more time, because of retries.
49 using ClientContextFactory = utils::move_only_function<std::unique_ptr<grpc::ClientContext>() const>;
50 void SetClientContextFactory(ClientContextFactory&& client_context_factory);
51 /// @}
52
53private:
54 friend class impl::CallOptionsAccessor;
55
56 int attempts_{0};
57
58 std::chrono::milliseconds timeout_{std::chrono::milliseconds::max()};
59
60 std::vector<std::pair<grpc::string, grpc::string>> metadata_;
61
62 ClientContextFactory client_context_factory_;
63};
64
65} // namespace ugrpc::client
66
67USERVER_NAMESPACE_END