#pragma once #include #include #include #include #include namespace CurrentMetrics { extern const Metric KafkaProducers; } namespace DB { class Block; using ProducerPtr = std::shared_ptr; class WriteBufferToKafkaProducer : public WriteBuffer { public: WriteBufferToKafkaProducer( ProducerPtr producer_, const std::string & topic_, std::optional delimiter, size_t rows_per_message, size_t chunk_size_, std::chrono::milliseconds poll_timeout, const Block & header); ~WriteBufferToKafkaProducer() override; void countRow(const Columns & columns, size_t row); void flush(); private: void nextImpl() override; void addChunk(); void reinitializeChunks(); CurrentMetrics::Increment metric_increment{CurrentMetrics::KafkaProducers}; ProducerPtr producer; const std::string topic; const std::optional delim; const size_t max_rows; const size_t chunk_size; const std::chrono::milliseconds timeout; size_t rows = 0; std::list chunks; std::optional key_column_index; std::optional timestamp_column_index; }; }