userver: userver/kafka/consumer_component.hpp Source File
Loading...
Searching...
No Matches
consumer_component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/kafka/consumer_component.hpp
4/// @brief @copybrief kafka::ConsumerComponent
5
6#include <string_view>
7
8#include <userver/kafka/consumer_scope.hpp>
9
10#include <userver/components/component_base.hpp>
11#include <userver/utils/fast_pimpl.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace kafka {
16
17namespace impl {
18
19class Consumer;
20
21} // namespace impl
22
23/// @ingroup userver_components
24///
25/// @brief Apache Kafka Consumer client component.
26///
27/// ## Static configuration example:
28///
29/// @snippet samples/kafka_service/static_config.yaml Kafka service sample - consumer static config
30///
31/// ## Secdist format
32///
33/// A Kafka alias in secdist is described as a JSON object
34/// `kafka_settings`, containing credentials of Kafka brokers.
35///
36/// @snippet samples/kafka_service/testsuite/conftest.py Kafka service sample - secdist
37///
38/// ## Static options of kafka::ConsumerComponent :
39/// @include{doc} scripts/docs/en/components_schema/kafka/src/kafka/consumer_component.md
40///
41/// Options inherited from @ref components::ComponentBase :
42/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
43class ConsumerComponent final : public components::ComponentBase {
44public:
45 /// @ingroup userver_component_names
46 /// @brief The default name of kafka::ConsumerComponent component
47 static constexpr std::string_view kName{"kafka-consumer"};
48
49 ConsumerComponent(const components::ComponentConfig& config, const components::ComponentContext& context);
50 ~ConsumerComponent() override;
51
52 /// @brief Returns consumer instance.
53 /// @see kafka::ConsumerScope
54 ConsumerScope GetConsumer();
55
56 static yaml_config::Schema GetStaticConfigSchema();
57
58private:
59 static constexpr std::size_t kImplSize = 2480;
60 static constexpr std::size_t kImplAlign = 16;
61 utils::FastPimpl<impl::Consumer, kImplSize, kImplAlign> consumer_;
62};
63
64} // namespace kafka
65
66USERVER_NAMESPACE_END