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/// task-processor | the task processor for blocking channel creation | -
46/// channel-args | a map of channel arguments, see gRPC Core docs | {}
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/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
53
54// clang-format on
55
56class ClientFactoryComponent final : public components::ComponentBase {
57 public:
58 /// @ingroup userver_component_names
59 /// @brief The default name of ugrpc::client::middlewares::log::Component
60 static constexpr std::string_view kName = "grpc-client-factory";
61
62 ClientFactoryComponent(const components::ComponentConfig& config,
63 const components::ComponentContext& context);
64
65 ClientFactory& GetFactory();
66
67 static yaml_config::Schema GetStaticConfigSchema();
68
69 private:
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