userver: userver/kafka/consumer_scope.hpp Source File
Loading...
Searching...
No Matches
consumer_scope.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <functional>
7
12
13USERVER_NAMESPACE_BEGIN
14
15namespace kafka {
16
17namespace impl {
18
19class Consumer;
20
21} // namespace impl
22
68class ConsumerScope final {
69public:
76 using Callback = std::function<void(MessageBatchView)>;
77
80
81 ConsumerScope(ConsumerScope&&) noexcept = delete;
82 ConsumerScope& operator=(ConsumerScope&&) noexcept = delete;
83
85 const std::vector<std::string>& GetTopics() const;
86
94 void Start(Callback callback);
95
110 void Stop() noexcept;
111
122
133 utils::zstring_view topic,
134 std::uint32_t partition,
135 std::optional<std::chrono::milliseconds> timeout = std::nullopt
136 ) const;
137
146 std::vector<std::uint32_t> GetPartitionIds(
147 utils::zstring_view topic,
148 std::optional<std::chrono::milliseconds> timeout = std::nullopt
149 ) const;
150
157
164
178 void Seek(
179 utils::zstring_view topic,
180 std::uint32_t partition_id,
181 std::uint64_t offset,
182 std::chrono::milliseconds timeout
183 ) const;
184
196 void SeekToBeginning(utils::zstring_view topic, std::uint32_t partition_id, std::chrono::milliseconds timeout)
197 const;
198
210 void SeekToEnd(utils::zstring_view topic, std::uint32_t partition_id, std::chrono::milliseconds timeout) const;
211
212private:
213 friend class impl::Consumer;
214
215 explicit ConsumerScope(impl::Consumer& consumer) noexcept;
216
217 impl::Consumer& consumer_;
218};
219
220} // namespace kafka
221
222USERVER_NAMESPACE_END