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

Choose partition based on key #365

Closed
lhrolim opened this issue Sep 13, 2019 · 3 comments
Closed

Choose partition based on key #365

lhrolim opened this issue Sep 13, 2019 · 3 comments

Comments

@lhrolim
Copy link

lhrolim commented Sep 13, 2019

Is there any way to choose which partition to send a message based on a message key?

Other libraries seem to provide such feature out of the box:

https://github.com/SOHU-Co/kafka-node#sendpayloads-cb (node)
https://docs.spring.io/spring-kafka/api/org/springframework/kafka/core/KafkaTemplate.html#send-java.lang.String-java.lang.Integer-K-V- (java)

At this point, would we need to pick the topic metadata and implement the algorithm based on the key hash for instance?

@joshuawscott
Copy link
Member

KafkaEx uses murmur2 hashing by default, which matches the Java client.

If you want to define your own, you can look at https://hexdocs.pm/kafka_ex/KafkaEx.Partitioner.html - the default implementation of that is https://hexdocs.pm/kafka_ex/KafkaEx.DefaultPartitioner.html

@mjparrott
Copy link
Contributor

@joshuawscott Is the fact that KafkaEx uses the default partitioner (matching the Java client) documented anywhere? I was looking around to see what KafkaEx would do if I only provided the key and this issue is the only reference to this I could find.

@jbruggem
Copy link
Collaborator

jbruggem commented Mar 9, 2020

@mjparrott it is documented in the hex docs of KafkaEx.DefaultPartitioner.

If you believe it could be relevant to document it somewhere else, could you please provide a PR for that ? Thanks a lot !

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

4 participants