userver: userver/ydb/topic_writer_types.hpp Source File
Loading...
Searching...
No Matches
topic_writer_types.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ydb/topic_writer_types.hpp
4/// @brief Types for YDB topic writer
5
6#include <memory>
7#include <string>
8#include <string_view>
9#include <unordered_map>
10
11#include <ydb-cpp-sdk/client/topic/write_events.h>
12
13#include <userver/utils/impl/internal_tag.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace ydb {
18
19namespace impl {
20struct TopicWriterHandlingResult;
21}
22
23/// Metadata associated with a YDB topic message (key-value pairs)
24using TopicWriterMetadata = std::unordered_map<std::string, std::string>;
25
26/// YDB write acknowledgement event state.
27/// @see https://ydb.tech/docs/en/reference/ydb-sdk/topic#write
28using TopicWriteEventState = NYdb::NTopic::TWriteSessionEvent::TWriteAck::EEventState;
29
30/// @brief Provides status code for storing messages to the internal queue
32 /// Message has been put into the internal queue
34 /// Internal queue is full
36 /// Other error
38 /// Not used for the moment, we accept all messages for handling
40 /// @warning Do not use this value
42};
43
44/// @brief Provides the result of the message handling
45///
46/// @note Although initially this interface was intended to be awaitable,
47/// underlying YDB driver doesn't support waiting for result without
48/// enabled deduplication.
50public:
51 /// @brief Constructs a write result
52 /// @param status the status of the write operation
54
55 /// @cond
56 // For internal use only.
57 /// @brief Constructs a write result
58 /// @param status the status of the write operation
59 /// @param context internal handling result context (may be nullptr)
60 TopicWriteResult(
61 utils::impl::InternalTag,
62 TopicWriteStatus status,
63 std::shared_ptr<impl::TopicWriterHandlingResult> context
64 );
65 /// @endcond
66
67 /// Status of whether the message has been accepted for handling by the
68 /// library. Note that this status does not reflect the result of the
69 /// message processing by YDB itself.
70 TopicWriteStatus GetStatus() const { return status_; }
71
72private:
73 TopicWriteStatus status_;
74 std::shared_ptr<impl::TopicWriterHandlingResult> context_;
75};
76
77/// @brief Converts TopicWriteStatus to a human-readable string view
78/// @param status the status to convert
79/// @return string_view representation of the status
80std::string_view ToStringView(TopicWriteStatus status);
81
82} // namespace ydb
83
84USERVER_NAMESPACE_END