-
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 1 commit
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 |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
* | ||
*/ | ||
#include <sstream> | ||
#include <algorithm> | ||
#include <cctype> | ||
#include "consumer.h" | ||
#include "exceptions.h" | ||
#include "logging.h" | ||
|
@@ -39,6 +41,8 @@ using std::move; | |
using std::make_tuple; | ||
using std::ostringstream; | ||
using std::chrono::milliseconds; | ||
using std::toupper; | ||
using std::equal; | ||
|
||
namespace cppkafka { | ||
|
||
|
@@ -48,6 +52,23 @@ void Consumer::rebalance_proxy(rd_kafka_t*, rd_kafka_resp_err_t error, | |
static_cast<Consumer*>(opaque)->handle_rebalance(error, list); | ||
} | ||
|
||
TopicPartitionList Consumer::get_matching_partitions(TopicPartitionList&& partitions, | ||
const vector<string>& topics) { | ||
TopicPartitionList matches; | ||
for (const auto& topic : topics) { | ||
for (auto& partition : partitions) { | ||
bool match = equal(topic.begin(), topic.end(), partition.get_topic().begin(), | ||
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. Won't this blow up if 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. Yeah looks like the signature was improved in C++17 with a fourth end iterator. I'll put a boundary check. |
||
[](char c1, char c2)->bool { | ||
return toupper(c1) == toupper(c2); | ||
}); | ||
if (match) { | ||
matches.emplace_back(move(partition)); | ||
} | ||
} | ||
} | ||
return matches; | ||
} | ||
|
||
Consumer::Consumer(Configuration config) | ||
: KafkaHandleBase(move(config)) { | ||
char error_buffer[512]; | ||
|
@@ -125,6 +146,22 @@ void Consumer::unassign() { | |
check_error(error); | ||
} | ||
|
||
void Consumer::pause() { | ||
pause_partitions(get_assignment()); | ||
} | ||
|
||
void Consumer::pause_topics(const std::vector<string>& 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. No |
||
pause_partitions(get_matching_partitions(get_assignment(), topics)); | ||
} | ||
|
||
void Consumer::resume() { | ||
resume_partitions(get_assignment()); | ||
} | ||
|
||
void Consumer::resume_topics(const std::vector<string>& topics) { | ||
resume_partitions(get_matching_partitions(get_assignment(), topics)); | ||
} | ||
|
||
void Consumer::commit() { | ||
commit(nullptr, false); | ||
} | ||
|
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.
Why is this an rvalue reference and not a const ref?
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.
I move it internally. I don't need to make a copy. The return of
get_assignement
is passed-in directly as an rvalue. Unless you think you may need to use this function elsewhere in the class...?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.
I didn't see the move. But anyway, in that case it should be taken by value, not by rvalue ref. The value will be moved into this function so won't be making any copies.