Skip to content
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

Add custom partitioner in the producer? #211

Open
joelmunoz opened this issue Jun 29, 2023 · 4 comments
Open

Add custom partitioner in the producer? #211

joelmunoz opened this issue Jun 29, 2023 · 4 comments

Comments

@joelmunoz
Copy link

Currently, there is not way to add a custom partitioner using modern-cpp-kafka. What should I do in order to add this feature? Or Is there any release where this feature is available?

@kenneth-jia
Copy link
Contributor

Actually, you're free to implement your customized partitioner and set it for a ProducerRecord (before sending the record). https://github.com/morganstanley/modern-cpp-kafka/blob/main/include/kafka/ProducerRecord.h#L43

@joelmunoz
Copy link
Author

However, it does not work as

RdKafka::Conf* conf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
CustomPartitioner partitioner;
conf->set("partitioner_cb", &partitioner, errstr);

In this way, the number of partitions of the target topic is provided by library itself (Java version uses a similar mechanism). On the other hand, using the ProducerRecord, I have to fetch topics metada in order to provide that information.

@kenneth-jia
Copy link
Contributor

kenneth-jia commented Jun 30, 2023

On the other hand, using the ProducerRecord, I have to fetch topics metada in order to provide that information

That's a good point!

@joelmunoz
Copy link
Author

joelmunoz commented Jun 30, 2023

@kenneth-jia That is the reason I want to add this feature. I want to use the same idea used for "stats_cb", but for "partitioner_cb". However, before to develop it, I wanted to ask if you, as dev & maintainer, suggest another path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants