-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Can you explain a bit about the 'key' passed by the producer? #42
Comments
The main use of the key is for partitioning: it is used in combination with a specific partitioner to make sure that messages with a certain key goes to the same partition. For example, say that we are making a user authentication monitor and for each login attempt a message is logged through kafka. The key is set to the username. On the other hand if all we need is load balancing - spread messages equally over all partitioners - then the key is You could use it as a header, the key is just a binary blob, the broker does not act on the key in any way, it is simply attached to the message and provided with the message to consumers. |
sounds good, thanks. The reason I want to use it as a header is that I need to add some metadata about what it is I'm sending as the message, and I don't want to send that metadata as part of the actual message payload (for a couple of reasons. 1 - I want the information to be optional and the consumer to ignore it if he doesn't care. 2 - I don't want to have to do any 'escaping' of the payload contents due to the nature of the 'envelope' I would have had to create inside the payload. For example, if my envelope was in JSON, I would then have to ensure that my payload was escaped to avoid JSON parson problems, etc.). |
I know it can be used by the partitioner, but I'm also wondering what other value it has - I read that it is also passed to the consumer. Could this be considered like a 'header field'? (thinking like a JMS Header field). Is there only a single key that can be passed? If so, I guess I would have to make it somewhat of a compound/concatenated/delimited one if I want to have a bunch of properties passed?
The text was updated successfully, but these errors were encountered: