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