mirror of
https://github.com/Telecominfraproject/wlan-cloud-lib-cppkafka.git
synced 2025-11-01 19:18:04 +00:00
Handle producer queue being full on buffered producer
This commit is contained in:
@@ -171,13 +171,29 @@ unsigned BufferedProducer<BufferType>::get_topic_index(const std::string& topic)
|
|||||||
template <typename BufferType>
|
template <typename BufferType>
|
||||||
void BufferedProducer<BufferType>::produce_message(IndexType index,
|
void BufferedProducer<BufferType>::produce_message(IndexType index,
|
||||||
const BufferedMessage& message) {
|
const BufferedMessage& message) {
|
||||||
if (message.key) {
|
bool sent = false;
|
||||||
producer_.produce(topics_[message.topic_index], message.partition, *message.key,
|
while (!sent) {
|
||||||
message.payload, reinterpret_cast<void*>(index));
|
try {
|
||||||
}
|
if (message.key) {
|
||||||
else {
|
producer_.produce(topics_[message.topic_index], message.partition, *message.key,
|
||||||
producer_.produce(topics_[message.topic_index], message.partition, {} /*key*/,
|
message.payload, reinterpret_cast<void*>(index));
|
||||||
message.payload, reinterpret_cast<void*>(index));
|
}
|
||||||
|
else {
|
||||||
|
producer_.produce(topics_[message.topic_index], message.partition, {} /*key*/,
|
||||||
|
message.payload, reinterpret_cast<void*>(index));
|
||||||
|
}
|
||||||
|
sent = true;
|
||||||
|
}
|
||||||
|
catch (const HandleException& ex) {
|
||||||
|
const Error error = ex.get_error();
|
||||||
|
if (error == RD_KAFKA_RESP_ERR__QUEUE_FULL) {
|
||||||
|
// If the output queue is full, then just poll
|
||||||
|
producer_.poll();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user