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 {
30 public:
31 /// @cond
32 // For internal use only.
33 explicit TopicReadSession(
34 std::shared_ptr<NYdb::NTopic::IReadSession> read_session);
35 /// @endcond
36
37 /// @brief Get read session events
38 ///
39 /// Waits until event occurs
40 /// @param max_events_count maximum events count in batch
41 /// if not specified, read session chooses event batch size automatically
44
45 /// @brief Close read session
46 ///
47 /// Waits for all commit acknowledgments to arrive.
48 /// Force close after timeout
49 bool Close(std::chrono::milliseconds timeout);
50
51 /// Get native read session
52 /// @warning Use with care! Facilities from
53 /// `<core/include/userver/drivers/subscribable_futures.hpp>` can help with
54 /// non-blocking wait operations.
56
57 private:
58 std::shared_ptr<NYdb::NTopic::IReadSession> read_session_;
59};
60
61/// @ingroup userver_clients
62///
63/// @brief YDB Topic Client
64///
65/// @see https://ydb.tech/docs/en/concepts/topic
66class TopicClient final {
67 public:
68 /// @cond
69 // For internal use only.
70 TopicClient(std::shared_ptr<impl::Driver> driver,
71 impl::TopicSettings settings);
72 /// @endcond
73
74 ~TopicClient();
75
76 /// Alter topic
77 void AlterTopic(const std::string& path,
78 const NYdb::NTopic::TAlterTopicSettings& settings);
79
80 /// Describe topic
82
83 /// Create read session
84 TopicReadSession CreateReadSession(
85 const NYdb::NTopic::TReadSessionSettings& settings);
86
87 /// Get native topic client
88 /// @warning Use with care! Facilities from
89 /// `<core/include/userver/drivers/subscribable_futures.hpp>` can help with
90 /// non-blocking wait operations.
92
93 private:
94 std::shared_ptr<impl::Driver> driver_;
95 NYdb::NTopic::TTopicClient topic_client_;
96};
97
98} // namespace ydb
99
100USERVER_NAMESPACE_END