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