userver: userver/ugrpc/client/client_factory_component.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
client_factory_component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/client/client_factory_component.hpp
4/// @brief @copybrief ugrpc::client::ClientFactoryComponent
5
6#include <userver/components/loggable_component_base.hpp>
7
8#include <userver/ugrpc/client/client_factory.hpp>
9#include <userver/ugrpc/client/queue_holder.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace ugrpc::client {
14
15/// @ingroup userver_components
16///
17/// @brief Provides a ClientFactory in the component system
18///
19/// Multiple ClientFactoryComponent instances may be created if different
20/// parameters are required for different clients.
21///
22/// ## Authentication
23/// Authentication is controlled by `auth-type` static config field.
24/// Possible values:
25/// - `insecure` (`InsecureChannelCredentials` - default)
26/// - `ssl` (`SslCredentials`)
27///
28/// Default (system) authentication keys are used regardless of the chosen
29/// auth-type.
30///
31/// ## Service config
32/// As per https://github.com/grpc/grpc/blob/master/doc/service_config.md
33/// service config should be distributed via the name resolution process.
34/// We allow setting default service_config: pass desired JSON literal
35/// to `default-service-config` parameter
36
37// clang-format off
38
39/// ## Static options:
40/// The default component name for static config is `"grpc-client-factory"`.
41///
42/// Name | Description | Default value
43/// ---- | ----------- | -------------
44/// task-processor | the task processor for blocking channel creation | -
45/// channel-args | a map of channel arguments, see gRPC Core docs | {}
46/// native-log-level | min log level for the native gRPC library | 'error'
47/// auth-type | authentication method, see above | -
48/// default-service-config | default service config, see above | -
49/// channel-count | Number of underlying grpc::Channel objects | 1
50/// middlewares | middlewares names to use | []
51///
52///
53/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
54
55// clang-format on
56
57class ClientFactoryComponent final : public components::LoggableComponentBase {
58 public:
59 static constexpr std::string_view kName = "grpc-client-factory";
60
61 ClientFactoryComponent(const components::ComponentConfig& config,
62 const components::ComponentContext& context);
63
64 ClientFactory& GetFactory();
65
66 static yaml_config::Schema GetStaticConfigSchema();
67
68 private:
69 std::optional<QueueHolder> queue_;
70 std::optional<ClientFactory> factory_;
71};
72
73} // namespace ugrpc::client
74
75template <>
76inline constexpr bool
77 components::kHasValidate<ugrpc::client::ClientFactoryComponent> = true;
78
79USERVER_NAMESPACE_END