userver: userver/ugrpc/client/client_factory_component.hpp Source File
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/component_base.hpp>
7#include <userver/middlewares/runner.hpp>
8
9#include <userver/ugrpc/client/client_factory.hpp>
10#include <userver/ugrpc/client/middlewares/base.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace ugrpc::client {
15
16namespace impl {
17
18/// @brief The interface for a `ClientFactoryComponent` component. So, `ClientFactoryComponent` runs with middlewares.
19using MiddlewareRunner = USERVER_NAMESPACE::middlewares::RunnerComponentBase<MiddlewareBase, ClientInfo>;
20
21} // namespace impl
22
23// clang-format off
24
25/// @ingroup userver_components
26///
27/// @brief Provides a ClientFactory in the component system
28///
29/// Multiple ClientFactoryComponent instances may be created if different
30/// parameters are required for different clients.
31///
32/// Requires ugrpc::client::CommonComponent.
33///
34/// ## Authentication
35/// Authentication is controlled by `auth-type` static config field.
36/// Possible values:
37/// - `insecure` (`InsecureChannelCredentials` - default)
38/// - `ssl` (`SslCredentials`)
39///
40/// Default (system) authentication keys are used regardless of the chosen
41/// auth-type.
42///
43/// ## Service config
44/// As per https://github.com/grpc/grpc/blob/master/doc/service_config.md
45/// service config should be distributed via the name resolution process.
46/// We allow setting default service_config: pass desired JSON literal
47/// to `default-service-config` parameter
48///
49/// ## Static options:
50/// The default component name for static config is `"grpc-client-factory"`.
51///
52/// Name | Description | Default value
53/// ---- | ----------- | -------------
54/// channel-args | a map of channel arguments, see gRPC Core docs | {}
55/// auth-type | authentication method, see above | -
56/// default-service-config | default service config, see above | -
57/// channel-count | Number of underlying grpc::Channel objects | 1
58/// middlewares | middlewares names to use | -
59/// disable-user-pipeline-middlewares | a flag to disable groups::User middlewares from pipeline | false
60/// disable-all-pipeline-middlewares | a flag to disable all middlewares from the pipline | false
61///
62/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
63
64// clang-format on
65
66class ClientFactoryComponent final : public impl::MiddlewareRunner {
67public:
68 /// @ingroup userver_component_names
69 /// @brief The default name of ugrpc::client::middlewares::log::Component
70 static constexpr std::string_view kName = "grpc-client-factory";
71
72 ClientFactoryComponent(const components::ComponentConfig& config, const components::ComponentContext& context);
73
74 ClientFactory& GetFactory();
75
76 static yaml_config::Schema GetStaticConfigSchema();
77
78private:
79 std::optional<ClientFactory> factory_;
80};
81
82} // namespace ugrpc::client
83
84template <>
85inline constexpr bool components::kHasValidate<ugrpc::client::ClientFactoryComponent> = true;
86
87USERVER_NAMESPACE_END