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