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