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

#include <userver/ydb/topic.hpp>

Detailed Description

Native YDB producer used for partition-aware writes to a topic.

Unlike TopicSimpleWriteSession, this is a wrapper around the YDB SDK IProducer. It selects partitions by message key or explicit partition and manages the corresponding write sessions internally.

Write() fails immediately if the internal buffer is overloaded.

The SDK close call runs on the blocking task processor and suspends the calling coroutine until it completes. It requires a userver coroutine context. Destruction and move assignment close an existing producer if ydb::TopicProducer::Close has not been called.

Warning
The destruction timeout configured with ydb::TopicProducerSettings::CloseTimeout defaults to zero: pending messages are not guaranteed to be delivered.
See also
https://ydb.tech/docs/en/reference/ydb-sdk/topic#write

Definition at line 239 of file topic.hpp.

Public Member Functions

 TopicProducer (const TopicProducer &)=delete
 TopicProducer (TopicProducer &&) noexcept
TopicProducer & operator= (const TopicProducer &)=delete
TopicProducer & operator= (TopicProducer &&) noexcept
NYdb::NTopic::TWriteResult Write (NYdb::NTopic::TWriteMessage &&message)
 Write a single message to the topic.
NYdb::NTopic::TFlushResult Flush (engine::Deadline deadline={})
 Flush all buffered messages to the server.
NYdb::NTopic::TCloseResult Close (std::chrono::milliseconds timeout)
 Close the producer.
NYdb::NTopic::IProducer & GetNativeTopicProducer ()
 Get native producer.

Member Function Documentation

◆ Close()

NYdb::NTopic::TCloseResult ydb::TopicProducer::Close ( std::chrono::milliseconds timeout)

Close the producer.

Waits for all in-flight messages to be acknowledged. Force closes after timeout. Repeated calls return AlreadyClosed.

◆ Flush()

NYdb::NTopic::TFlushResult ydb::TopicProducer::Flush ( engine::Deadline deadline = {})

Flush all buffered messages to the server.

Waits until all in-flight messages are acknowledged.

Parameters
deadlinetimeout for flush completion

◆ GetNativeTopicProducer()

NYdb::NTopic::IProducer & ydb::TopicProducer::GetNativeTopicProducer ( )

Get native producer.

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

◆ Write()

NYdb::NTopic::TWriteResult ydb::TopicProducer::Write ( NYdb::NTopic::TWriteMessage && message)

Write a single message to the topic.

Adds the message to the internal buffer and returns its queueing status. Fails immediately with EWriteStatus::Timeout if the buffer is full. Use Flush() to wait for the buffered messages to be persistently written.


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