Skip to content

Instantly share code, notes, and snippets.

@aeppert
Last active April 12, 2018 16:49
Show Gist options
  • Save aeppert/9a623fb6973696e45f8074353796370a to your computer and use it in GitHub Desktop.
Save aeppert/9a623fb6973696e45f8074353796370a to your computer and use it in GitHub Desktop.
librdkafka round-robin partitioner
class RRPartitionerCb : public RdKafka::PartitionerCb {
public:
RRPartitionerCb() { partition = 0; }
int32_t partitioner_cb(const RdKafka::Topic *topic,
const std::string *key,
int32_t partition_cnt,
void *msg_opaque) {
if((partition+1) > (partition_cnt-1)) {
partition = 0;
return partition;
}
partition++;
return partition;
}
private:
int32_t partition;
};
@aeppert
Copy link
Author

aeppert commented Apr 12, 2018

Ah, indeed you would be correct. That is the simplification. This is what happens when one writes code at 1AM takes a nap and still has the over-complicated logic in one's head... Thank you for that!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment