userver: userver/ydb/topic.hpp Source File
Loading...
Searching...
No Matches
topic.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ydb/topic.hpp
4/// @brief YDB Topic client
5
6#include <chrono>
7#include <memory>
8#include <string>
9
10#include <ydb-cpp-sdk/client/topic/client.h>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace ydb {
15
16namespace impl {
17class Driver;
18struct TopicSettings;
19} // namespace impl
20
21/// @brief Read session used to connect to one or more topics for reading
22///
23/// @see https://ydb.tech/docs/en/reference/ydb-sdk/topic#reading
24///
25/// ## Example usage:
26///
27/// @snippet userver/samples/ydb_service/components/topic_reader.hpp Sample
28/// Topic reader
29class TopicReadSession final {
30public:
31 /// @cond
32 // For internal use only.
33 explicit TopicReadSession(std::shared_ptr<NYdb::NTopic::IReadSession> read_session);
34 /// @endcond
35
36 /// @brief Get read session events
37 ///
38 /// Waits until event occurs
39 /// @param max_events_count maximum events count in batch
40 /// if not specified, read session chooses event batch size automatically
42
43 /// @brief Close read session
44 ///
45 /// Waits for all commit acknowledgments to arrive.
46 /// Force close after timeout
47 bool Close(std::chrono::milliseconds timeout);
48
49 /// Get native read session
50 /// @warning Use with care! Facilities from
51 /// `<core/include/userver/drivers/subscribable_futures.hpp>` can help with
52 /// non-blocking wait operations.
54
55private:
56 std::shared_ptr<NYdb::NTopic::IReadSession> read_session_;
57};
58
59/// @ingroup userver_clients
60///
61/// @brief YDB Topic Client
62///
63/// @see https://ydb.tech/docs/en/concepts/topic
64class TopicClient final {
65public:
66 /// @cond
67 // For internal use only.
68 TopicClient(std::shared_ptr<impl::Driver> driver, impl::TopicSettings settings);
69 /// @endcond
70
71 ~TopicClient();
72
73 /// Alter topic
74 void AlterTopic(const std::string& path, const NYdb::NTopic::TAlterTopicSettings& settings);
75
76 /// Describe topic
78
79 /// Create read session
80 TopicReadSession CreateReadSession(const NYdb::NTopic::TReadSessionSettings& settings);
81
82 /// Get native topic client
83 /// @warning Use with care! Facilities from
84 /// `<core/include/userver/drivers/subscribable_futures.hpp>` can help with
85 /// non-blocking wait operations.
87
88private:
89 std::shared_ptr<impl::Driver> driver_;
90 NYdb::NTopic::TTopicClient topic_client_;
91};
92
93} // namespace ydb
94
95USERVER_NAMESPACE_END