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;
16class MessageHolder;
17
18} // namespace impl
19
20/// @brief Wrapper for polled message data access.
21class Message final {
22public:
23 ~Message();
24
25 Message(Message&&) noexcept;
26 Message& operator=(Message&&) noexcept = delete;
27
28 Message(const Message&) = delete;
29 Message& operator=(const Message&) = delete;
30
31 const std::string& GetTopic() const;
32 std::string_view GetKey() const;
33 std::string_view GetPayload() const;
34 std::optional<std::chrono::milliseconds> GetTimestamp() const;
35 int GetPartition() const;
36 std::int64_t GetOffset() const;
37
38private:
39 friend class impl::ConsumerImpl;
40
41 explicit Message(impl::MessageHolder&& message);
42
43 struct MessageData;
44 using DataStorage = utils::FastPimpl<MessageData, 72, 8>;
45
46 DataStorage data_;
47};
48
49using MessageBatchView = utils::span<const Message>;
50
51} // namespace kafka
52
53USERVER_NAMESPACE_END