-
Notifications
You must be signed in to change notification settings - Fork 217
Pause/resume a consumer by topic #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d3c8ad9
4087416
e2f2cfc
739dcda
18d1198
dd8422d
86c8b59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,12 +28,14 @@ | |
*/ | ||
|
||
#include <iostream> | ||
#include <string> | ||
#include "topic_partition_list.h" | ||
#include "topic_partition.h" | ||
#include "exceptions.h" | ||
|
||
using std::vector; | ||
using std::ostream; | ||
using std::string; | ||
|
||
namespace cppkafka { | ||
|
||
|
@@ -67,6 +69,42 @@ TopicPartitionsListPtr make_handle(rd_kafka_topic_partition_list_t* handle) { | |
return TopicPartitionsListPtr(handle, &rd_kafka_topic_partition_list_destroy); | ||
} | ||
|
||
TopicPartitionList make_subset(const TopicPartitionList& partitions, | ||
const vector<string>& topics) { | ||
vector<bool> skip(partitions.size(), false); | ||
TopicPartitionList subset; | ||
for (const auto& topic : topics) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you flip this loop (first over partitions, then over topics), won't you get rid of the |
||
for (size_t i = 0; i < partitions.size(); ++i) { | ||
if (!skip[i] && (topic.size() == partitions[i].get_topic().size())) { | ||
// compare both strings | ||
bool match = equal(topic.begin(), topic.end(), partitions[i].get_topic().begin(), | ||
[](char c1, char c2)->bool { | ||
return toupper(c1) == toupper(c2); | ||
}); | ||
if (match) { | ||
skip[i] = true; | ||
subset.emplace_back(partitions[i]); | ||
} | ||
} | ||
} | ||
} | ||
return subset; | ||
} | ||
|
||
TopicPartitionList make_subset(const TopicPartitionList& partitions, | ||
const vector<int>& ids) { | ||
TopicPartitionList subset; | ||
for (const auto& id : ids) { | ||
for (const auto& partition : partitions) { | ||
// compare both partition ids | ||
if (id == partition.get_partition()) { | ||
subset.emplace_back(partition); | ||
} | ||
} | ||
} | ||
return subset; | ||
} | ||
|
||
ostream& operator<<(ostream& output, const TopicPartitionList& rhs) { | ||
output << "[ "; | ||
for (auto iter = rhs.begin(); iter != rhs.end(); ++iter) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay here but I'm not sure about the name, "make_subset" doesn't really explain what the function does. Maybe
find_matches
or something like that? As much as this does return a subset of the input, the important thing is how the subset is created and not the fact that it will return a subset.