userver: userver/ugrpc/client/client_factory_component.hpp Source File
Loading...
Searching...
No Matches
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 MiddlewareRunnerComponentBase = 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/// auth-type | authentication method, see @ref grpc_ssl_authentication "Authentication" | -
55/// ssl-credentials-options | TLS/SSL options, see @ref grpc_ssl_authentication "Authentication" | -
56/// retry-config | retry configuration for outgoing RPCs | {}
57/// channel-args | a map of channel arguments, see gRPC Core docs | {}
58/// default-service-config | default service config, see above | -
59/// channel-count | Number of underlying grpc::Channel objects | 1
60/// middlewares | middlewares names to use | -
61/// disable-user-pipeline-middlewares | a flag to disable groups::User middlewares from pipeline | false
62/// disable-all-pipeline-middlewares | a flag to disable all middlewares from the pipeline | false
63///
64/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
65
66// clang-format on
67
68class ClientFactoryComponent final : public impl::MiddlewareRunnerComponentBase {
69public:
70 /// @ingroup userver_component_names
71 /// @brief The default name of ugrpc::client::middlewares::log::Component
72 static constexpr std::string_view kName = "grpc-client-factory";
73
74 ClientFactoryComponent(const components::ComponentConfig& config, const components::ComponentContext& context);
75
76 ClientFactory& GetFactory();
77
78 static yaml_config::Schema GetStaticConfigSchema();
79
80private:
81 std::optional<ClientFactory> factory_;
82};
83
84} // namespace ugrpc::client
85
86template <>
87inline constexpr bool components::kHasValidate<ugrpc::client::ClientFactoryComponent> = true;
88
89USERVER_NAMESPACE_END