userver: userver/kafka/message.hpp Source File
Loading...
Searching...
No Matches
message.hpp
1#pragma once
2
3#include <chrono>
4#include <optional>
5
6#include <userver/utils/fast_pimpl.hpp>
7#include <userver/utils/span.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace kafka {
12
13namespace impl {
14
15class ConsumerImpl;
16
17} // namespace impl
18
19/// @brief RAII wrapper for polled message data.
20/// @note All `Message` instances must be destroyed before `Consumer` stop
21class Message final {
22 struct Data;
23 using DataStorage = utils::FastPimpl<Data, 16 + 32 + 16, 8>;
24
25 public:
26 ~Message();
27
28 Message(Message&&) = default;
29
30 const std::string& GetTopic() const;
31 std::string_view GetKey() const;
32 std::string_view GetPayload() const;
33 std::optional<std::chrono::milliseconds> GetTimestamp() const;
34 int GetPartition() const;
35 std::int64_t GetOffset() const;
36
37 private:
38 friend class impl::ConsumerImpl;
39
40 explicit Message(DataStorage data);
41
42 DataStorage data_;
43};
44
45using MessageBatchView = utils::span<const Message>;
46
47} // namespace kafka
48
49USERVER_NAMESPACE_END