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/loggable_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///
38/// @see https://grpc.github.io/grpc/core/group__grpc__arg__keys.html
39
40// clang-format on
41class ServerComponent final : public components::LoggableComponentBase {
42 public:
43 /// @ingroup userver_component_names
44 /// @brief The default name of ugrpc::server::ServerComponent
45 static constexpr std::string_view kName = "grpc-server";
46
47 ServerComponent(const components::ComponentConfig& config,
48 const components::ComponentContext& context);
49
50 ~ServerComponent() override;
51
52 /// @returns The contained Server instance
53 /// @note All configuration must be performed at the components loading stage
54 Server& GetServer() noexcept;
55
56 /// @cond
57 ServiceConfig ParseServiceConfig(const components::ComponentConfig& config,
58 const components::ComponentContext& context);
59 /// @endcond
60
61 static yaml_config::Schema GetStaticConfigSchema();
62
63 private:
64 void OnAllComponentsLoaded() override;
65
66 void OnAllComponentsAreStopping() override;
67
68 Server server_;
69 std::unique_ptr<impl::ServiceDefaults> service_defaults_;
70};
71
72} // namespace ugrpc::server
73
74template <>
75inline constexpr bool components::kHasValidate<ugrpc::server::ServerComponent> =
76 true;
77
78USERVER_NAMESPACE_END