KafkaJS and java producer partitioning returning different results
See original GitHub issueProducing message with the same key gets assigned to different partitions depending if app is using java or nodejs client.
This creates problems when using kafka streams for joining those data - meeting the co-partitioning requirement fails even when message keys are the same.
I created an isolated test code which confirmed it. Simple java and nodejs app with partitioning using murmur2 code extracted from the latest kafkajs and java producer. The code looks the same, but results differ. Even checked that input bytes are equal. ¯_(ツ)_/¯
Test runner result matches the partition number I’m seeing in Kafka broker…
Any idea why and can it be fixed?
Our current workaround is to repartition all kafkajs based messages with java producer…
let key = '100:48069';
let numPartitions = 12;
node bytes {"type":"Buffer","data":[49,48,48,58,52,56,48,54,57]}
node murmur 1713501762
node hash 1713501762
node partition 6
java bytes 49 48 48 58 52 56 48 54 57
java murmur 1009543857
java hash 1009543857
java partition 9
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Producing Messages - KafkaJS
To publish messages to Kafka you have to create a producer. Simply call the producer function of the client to create it: const...
Read more >Solving My Weird Kafka Rebalancing Problems & Explaining ...
While Kafka is rebalancing, all involved consumers' processing is blocked (Incremental rebalancing aims to revoke only partitions that need to ...
Read more >How could I properly pause/resume considering the ...
I have a topic with 10 partitions. Producer. One producer publishes messages to the Kafka cluster, distributing them among partitions according ...
Read more >Top 5 Things Every Apache Kafka Developer Should Know
In other words, these in-sync replicas have the same content for a given topic ... In this case, the producer always uses this...
Read more >Documentation - Apache Kafka
We provide a java client for Kafka, but clients are available in many ... The producer is able to choose which message to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Tried it out. Works! Thank you very much for so fast fix
I couldn’t stop myself, because this is fascinating. I found where the issue is, though I don’t understand it yet.
https://github.com/tulios/kafkajs/blob/c5ab8c229369ae4966ffd3ce22e2b0c00191943b/src/producer/partitioners/default/murmur2.js#L28
I ran some interactive debugging of both the Java and JS implementations, executing them side-by side and comparing the values. On this line, the values diverge between the JS and Java implementations. Given the key you provided, on the first iteration of the loop,
k
is976236593
andm
is1540483477
in both JS and Java, but after doingk *= M
, the value ofk
is2095687045
in Java and1503876341159274000
in JS.Essentially:
I’m assuming this is because we’re using the native
Number
type in Javascript, which has different limits from Java’sint
.