userver: ydb::TopicSimpleWriteSession Class Reference
Loading...
Searching...
No Matches
ydb::TopicSimpleWriteSession Class Referencefinal

#include <userver/ydb/topic.hpp>

Detailed Description

Simple write session used to write messages to a topic without manually handling write session events.

This is a userver-native analogue of YDB SDK ISimpleBlockingWriteSession: methods may wait for YDB flow-control continuation tokens, but waiting suspends the current coroutine instead of blocking an OS thread. It wraps a single IWriteSession; its simple API does not expose the native event loop or acknowledgments.

See also
https://ydb.tech/docs/en/reference/ydb-sdk/topic#write

Definition at line 137 of file topic.hpp.

Public Member Functions

 TopicSimpleWriteSession (const TopicSimpleWriteSession &)=delete
TopicSimpleWriteSession & operator= (const TopicSimpleWriteSession &)=delete
 TopicSimpleWriteSession (TopicSimpleWriteSession &&) noexcept
TopicSimpleWriteSession & operator= (TopicSimpleWriteSession &&) noexcept
bool Write (NYdb::NTopic::TWriteMessage &&message, NYdb::TTransactionBase *tx=nullptr, engine::Deadline deadline={})
 Write a single message.
bool Write (std::string_view data, std::optional< std::uint64_t > seq_no=std::nullopt, std::optional< std::chrono::system_clock::time_point > create_timestamp=std::nullopt, engine::Deadline deadline={})
 Write a single message using basic message options.
std::uint64_t GetInitSeqNo (engine::Deadline deadline={})
 Wait until initial SeqNo is discovered from the server.
bool Close (std::chrono::milliseconds timeout)
 Close the write session.
bool IsAlive () const noexcept
 Returns true if the write session is alive and active.
NYdb::NTopic::IWriteSession & GetNativeTopicWriteSession ()
 Get native write session.

Member Function Documentation

◆ Close()

bool ydb::TopicSimpleWriteSession::Close ( std::chrono::milliseconds timeout)

Close the write session.

Waits for all in-flight messages to be acknowledged. Force closes after timeout.

Returns
true if all writes were completed and acknowledged. Returns false if the timeout expired and some writes were aborted; in that case their delivery is not guaranteed and should be handled as an application-level delivery failure.

◆ GetNativeTopicWriteSession()

NYdb::NTopic::IWriteSession & ydb::TopicSimpleWriteSession::GetNativeTopicWriteSession ( )

Get native write session.

Warning
Use with care! Facilities from userver/drivers/subscribable_futures.hpp can help with non-blocking wait operations.

◆ Write()

bool ydb::TopicSimpleWriteSession::Write ( NYdb::NTopic::TWriteMessage && message,
NYdb::TTransactionBase * tx = nullptr,
engine::Deadline deadline = {} )

Write a single message.

Waits until YDB provides a continuation token or until deadline.

Returns
true if the message was enqueued for writing, false if the deadline was reached or the session was closed before a token arrived.

The documentation for this class was generated from the following file: