File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
202202 /* *
203203 * \brief Resumes all consumption
204204 */
205- void resume ();
205+ void resume ();
206206
207207 /* *
208208 * \brief Commits the current partition assignment
Original file line number Diff line number Diff line change @@ -155,6 +155,20 @@ class CPPKAFKA_API Producer : public KafkaHandleBase {
155155 * \param timeout The timeout used on this call
156156 */
157157 void flush (std::chrono::milliseconds timeout);
158+
159+ /* *
160+ * \brief Pauses production for this topic
161+ *
162+ * \param topic The topic name
163+ */
164+ void pause (const std::string& topic);
165+
166+ /* *
167+ * \brief Resumes production for this topic
168+ *
169+ * \param topic The topic name
170+ */
171+ void resume (const std::string& topic);
158172private:
159173 PayloadPolicy message_payload_policy_;
160174};
Original file line number Diff line number Diff line change 3737#include < set>
3838#include < librdkafka/rdkafka.h>
3939#include " macros.h"
40+ #include " metadata.h"
4041
4142namespace cppkafka {
4243
@@ -53,6 +54,8 @@ using TopicPartitionList = std::vector<TopicPartition>;
5354CPPKAFKA_API TopicPartitionsListPtr convert (const TopicPartitionList& topic_partitions);
5455CPPKAFKA_API TopicPartitionList convert (const TopicPartitionsListPtr& topic_partitions);
5556CPPKAFKA_API TopicPartitionList convert (rd_kafka_topic_partition_list_t * topic_partitions);
57+ CPPKAFKA_API TopicPartitionList convert (const std::string& topic,
58+ const std::vector<PartitionMetadata>& partition_metadata);
5659CPPKAFKA_API TopicPartitionsListPtr make_handle (rd_kafka_topic_partition_list_t * handle);
5760
5861// Extracts a partition list subset belonging to the provided topics (case-insensitive)
Original file line number Diff line number Diff line change @@ -114,4 +114,12 @@ void Producer::flush(milliseconds timeout) {
114114 check_error (result);
115115}
116116
117+ void Producer::pause (const std::string& topic) {
118+ pause_partitions (convert (topic, get_metadata (get_topic (topic)).get_partitions ()));
119+ }
120+
121+ void Producer::resume (const std::string& topic) {
122+ resume_partitions (convert (topic, get_metadata (get_topic (topic)).get_partitions ()));
123+ }
124+
117125} // cppkafka
Original file line number Diff line number Diff line change @@ -66,6 +66,16 @@ TopicPartitionList convert(rd_kafka_topic_partition_list_t* topic_partitions) {
6666 return output;
6767}
6868
69+ TopicPartitionList convert (const std::string& topic,
70+ const std::vector<PartitionMetadata>& partition_metadata)
71+ {
72+ TopicPartitionList output;
73+ for (const auto & meta : partition_metadata) {
74+ output.emplace_back (topic, meta.get_id ());
75+ }
76+ return output;
77+ }
78+
6979TopicPartitionsListPtr make_handle (rd_kafka_topic_partition_list_t * handle) {
7080 return TopicPartitionsListPtr (handle, &rd_kafka_topic_partition_list_destroy);
7181}
You can’t perform that action at this time.
0 commit comments