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/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 /// @ingroup userver_component_names
60 /// @brief The default name of ugrpc::client::middlewares::log::Component
61 static constexpr std::string_view kName = "grpc-client-factory";
62
63 ClientFactoryComponent(const components::ComponentConfig& config,
64 const components::ComponentContext& context);
65
66 ClientFactory& GetFactory();
67
68 static yaml_config::Schema GetStaticConfigSchema();
69
70 private:
71 std::optional<QueueHolder> queue_;
72 std::optional<ClientFactory> factory_;
73};
74
75} // namespace ugrpc::client
76
77template <>
78inline constexpr bool
79 components::kHasValidate<ugrpc::client::ClientFactoryComponent> = true;
80
81USERVER_NAMESPACE_END