userver: userver/ugrpc/server/server_component.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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/// port | the port to use for all gRPC services, or 0 to pick any available | -
30/// unix-socket-path | unix socket absolute path to listen to, instead of listening on `port` | -
31/// completion-queue-count | count of completion queues to create | 2
32/// channel-args | a map of channel arguments, see gRPC Core docs | {}
33/// native-log-level | min log level for the native gRPC library | 'error'
34/// enable-channelz | initialize service with runtime info about gRPC connections | false
35/// service-defaults | default config values for gRPC services, see config schema | {}
36/// tls.cert | path to file with server TLS certificate | -
37/// tls.key | path to file with secret key from server TLS certificate | -
38/// tls.ca | path to TLS client CA certificate | -
39///
40/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
41
42// clang-format on
43class ServerComponent final : public components::ComponentBase {
44public:
45 /// @ingroup userver_component_names
46 /// @brief The default name of ugrpc::server::ServerComponent
47 static constexpr std::string_view kName = "grpc-server";
48
49 ServerComponent(const components::ComponentConfig& config, const components::ComponentContext& context);
50
51 ~ServerComponent() override;
52
53 /// @returns The contained Server instance
54 /// @note All configuration must be performed at the components loading stage
55 Server& GetServer() noexcept;
56
57 /// @cond
58 ServiceConfig
59 ParseServiceConfig(const components::ComponentConfig& config, const components::ComponentContext& context);
60 /// @endcond
61
62 static yaml_config::Schema GetStaticConfigSchema();
63
64private:
65 void OnAllComponentsLoaded() override;
66
67 void OnAllComponentsAreStopping() override;
68
69 Server server_;
70 std::unique_ptr<impl::ServiceDefaults> service_defaults_;
71};
72
73} // namespace ugrpc::server
74
75template <>
76inline constexpr bool components::kHasValidate<ugrpc::server::ServerComponent> = true;
77
78USERVER_NAMESPACE_END