-
Notifications
You must be signed in to change notification settings - Fork 628
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
Missing 'key' for message with 'key' field sends by Producer #699
Comments
Is it the bug here? messages = messages.map(function (message) {
if (message instanceof KeyedMessage) {
return message;
}
- return new Message(0, 0, '', message);
+ return new Message(0, 0, p.key || '', message);
}); I think it might because the |
After I changed it to [
{
"topic": "node-test6",
"key": "lowkey",
"value": "message 1",
"partition": 0,
"offset": 0
},
{
"topic": "node-test6",
"key": "highkey",
"value": "message 1",
"partition": 0,
"offset": 1
},
{
"topic": "node-test6",
"key": "lowkey",
"value": "message 2",
"partition": 0,
"offset": 2
},
{
"topic": "node-test6",
"key": "highkey",
"value": "message 2",
"partition": 0,
"offset": 3
},
{
"topic": "node-test6",
"key": "lowkey",
"value": "message 3",
"partition": 0,
"offset": 4
},
{
"topic": "node-test6",
"key": "highkey",
"value": "message 3",
"partition": 0,
"offset": 5
}
] |
fixes SOHU-Co#699 Signed-off-by: Tao Wang <twang2218@gmail.com>
I created a PR #700 for this issue. |
fixes SOHU-Co#699 Signed-off-by: Tao Wang <twang2218@gmail.com>
Hi @twang2218 lets continue our discussion here instead of on the PR. I believe we should allow any binary data for the key. In the past I thought perhaps a string key would be best (see #361) but since there's no restriction in the Kafka world we should treat it the same as messages are treated-- which is to let the user produce any binary data and the consumer define the output using the |
If we allow the Lines 41 to 50 in 8cba9d6
KeyedPartitioner.prototype.hashCode = function (string) {
var hash = 0;
var length = string.length;
for (var i = 0; i < length; i++) {
hash = ((hash * 31) + string.charCodeAt(i)) & 0x7fffffff;
}
return (hash === 0) ? 1 : hash;
}; But I do think the In Java client, when creating the props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer"); We can do the same, add 2 options in the As well as |
If a user is setting a I propose making the key consistent with how messages are treated.
Decoding it on the consumer side will depending on the |
Fixed in #704 and published as 2.0.0. Thanks for your help. |
Bug Report
In
producer.send(payload)
, if the payload is something like:the
key
should be the message key, ref: https://github.com/SOHU-Co/kafka-node#sendpayloads-cb-1However, the after checking the Kafka side, the key is missing.
Environment
v8.1.3
1.6.2
v0.10.2.1
For specific cases also provide
Include Sample Code to reproduce behavior
For the comparison, I also send a message which is
KeyedMessage
object.Here is the output of the
node index.js
However, on the Kafka side, the result is different:
As you can see, all the
lowkey
key are missing, only key in theKeyedMessage
are there.Thanks for your contribution!
The text was updated successfully, but these errors were encountered: