userver: userver/kafka/rebalance_types.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
rebalance_types.hpp
1#pragma once
2
3#include <cstdint>
4#include <functional>
5
6#include <userver/utils/span.hpp>
7#include <userver/utils/zstring_view.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace kafka {
12
13enum class RebalanceEventType { kAssigned, kRevoked };
14
15/// @brief Represents the topic's partition for certain topic.
16struct TopicPartitionView final {
17 /// @brief Topic's name.
18 utils::zstring_view topic;
19
20 /// @brief Partition ID for a topic
22
23 /// @brief Offset for current partition if it has commited offset
25
26 TopicPartitionView(utils::zstring_view topic, std::uint32_t partition_id, std::optional<std::uint64_t> offset)
27 : topic{topic}, partition_id{partition_id}, offset{offset} {}
28};
29
30using TopicPartitionBatchView = utils::span<const TopicPartitionView>;
31
32/// @brief Callback invoked when a rebalance event occurs.
33/// @warning The rebalance callback must be set before calling ConsumeScope::Start or after calling ConsumeScope::Stop .
34/// The callback must not throw exceptions; any thrown exceptions will be caught and logged by the consumer
35/// implementation.
36/// @note The callback is invoked after the assign or revoke event has been successfully processed.
37using ConsumerRebalanceCallback = std::function<void(TopicPartitionBatchView, RebalanceEventType)>;
38
39} // namespace kafka
40
41USERVER_NAMESPACE_END