#include <userver/kafka/producer.hpp>
Apache Kafka Producer Client.
It exposes the API to send an arbitrary message to the Kafka Broker to certain topic by given key and optional partition.
Message send tasks handling other messages' delivery reports, suspending their execution while no events exist. This makes message production parallel and leads to high Producer scalability.
Producer maintains per topic statistics including the broker connection errors.
delivery_timeout
to ensure all sent messages are properly delivered.Definition at line 57 of file producer.hpp.
Public Member Functions | |
~Producer () | |
Waits until all messages are sent for at most 2 x delivery_timeout and destroys the producer. | |
Producer (const Producer &)=delete | |
Producer (Producer &&)=delete | |
Producer & | operator= (const Producer &)=delete |
Producer & | operator= (Producer &&)=delete |
void | Send (const std::string &topic_name, std::string_view key, std::string_view message, std::optional< std::uint32_t > partition=kUnassignedPartition, HeaderViews headers={}) const |
Sends given message to topic topic_name by given key and partition (if passed) with payload contains the message data. Asynchronously waits until the message is delivered or the delivery error occurred. | |
engine::TaskWithResult< void > | SendAsync (std::string topic_name, std::string key, std::string message, std::optional< std::uint32_t > partition=kUnassignedPartition, HeaderViews headers={}) const |
Same as Producer::Send, but returns the task which can be used to wait the message delivery manually. | |
void | DumpMetric (utils::statistics::Writer &writer) const |
Dumps per topic messages produce statistics. No expected to be called manually. | |
kafka::Producer::~Producer | ( | ) |
Waits until all messages are sent for at most 2 x delivery_timeout
and destroys the producer.
void kafka::Producer::DumpMetric | ( | utils::statistics::Writer & | writer | ) | const |
Dumps per topic messages produce statistics. No expected to be called manually.
void kafka::Producer::Send | ( | const std::string & | topic_name, |
std::string_view | key, | ||
std::string_view | message, | ||
std::optional< std::uint32_t > | partition = kUnassignedPartition, | ||
HeaderViews | headers = {} ) const |
Sends given message to topic topic_name
by given key
and partition
(if passed) with payload contains the message
data. Asynchronously waits until the message is delivered or the delivery error occurred.
No payload data is copied. Method holds the data until message is delivered.
Thread-safe and can be called from any number of threads concurrently.
If partition
not passed, partition is chosen by internal Kafka partitioner.
enable_idempotence
option is enabled, do not use both explicit partitions and Kafka-chosen ones.SendException | and its descendants if message is not delivered and acked by Kafka Broker in configured timeout. |
|
nodiscard |
Same as Producer::Send, but returns the task which can be used to wait the message delivery manually.