userver: userver/ugrpc/server/server_component.hpp Source File
Loading...
Searching...
No Matches
server_component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/server/server_component.hpp
4/// @brief @copybrief ugrpc::server::ServerComponent
5
6#include <userver/components/component_base.hpp>
7
8#include <userver/ugrpc/server/server.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace ugrpc::server {
13
14namespace impl {
15struct ServiceDefaults;
16} // namespace impl
17
18// clang-format off
19
20/// @ingroup userver_components
21///
22/// @brief Component that configures and manages the gRPC server.
23///
24/// ## Static options:
25/// The component name for static config is `"grpc-server"`.
26///
27/// Name | Description | Default value
28/// ---- | ----------- | -------------
29/// access-tskv-logger | logger name for access-tskv.log | -
30/// port | the port to use for all gRPC services, or 0 to pick any available | -
31/// unix-socket-path | unix socket absolute path to listen to, instead of listening on `port` | -
32/// completion-queue-count | count of completion queues to create | 2
33/// channel-args | a map of channel arguments, see gRPC Core docs | {}
34/// native-log-level | min log level for the native gRPC library | 'error'
35/// enable-channelz | initialize service with runtime info about gRPC connections | false
36/// service-defaults | default config values for gRPC services, see config schema | {}
37/// tls.cert | path to file with server TLS certificate | -
38/// tls.key | path to file with secret key from server TLS certificate | -
39/// tls.ca | path to TLS client CA certificate | -
40///
41/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
42
43// clang-format on
44class ServerComponent final : public components::ComponentBase {
45public:
46 /// @ingroup userver_component_names
47 /// @brief The default name of ugrpc::server::ServerComponent
48 static constexpr std::string_view kName = "grpc-server";
49
50 ServerComponent(const components::ComponentConfig& config, const components::ComponentContext& context);
51
52 ~ServerComponent() override;
53
54 /// @returns The contained Server instance
55 /// @note All configuration must be performed at the components loading stage
56 Server& GetServer() noexcept;
57
58 /// @cond
59 ServiceConfig
60 ParseServiceConfig(const components::ComponentConfig& config, const components::ComponentContext& context);
61 /// @endcond
62
63 static yaml_config::Schema GetStaticConfigSchema();
64
65private:
66 void OnAllComponentsLoaded() override;
67
68 void OnAllComponentsAreStopping() override;
69
70 Server server_;
71 std::unique_ptr<impl::ServiceDefaults> service_defaults_;
72};
73
74} // namespace ugrpc::server
75
76template <>
77inline constexpr bool components::kHasValidate<ugrpc::server::ServerComponent> = true;
78
79USERVER_NAMESPACE_END