You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
jeffwidman
changed the title
Using the serializer recommended by the docs breaks producing with key=None
The serialization layer is processed before the producer's partitioning logic
Nov 29, 2018
jeffwidman
changed the title
The serialization layer is processed before the producer's partitioning logic
The serialization layer is unexpectedly processed before the producer's partitioning logic
Nov 29, 2018
Hmm, yes, totally agree, at least a set of helpers would be good. I still find it kind of strange that None is even passed to the serializer, not just left as None. But we can't just change that at this point.
StringSerializer and JsonSerializer would at least be great. There is still an open question about what do we do with headers. Java has calls to serialize those too.
sample code pulled from one of our internal applications:
Unsurprisingly, using
json.dumps
will serializekey=None
to'null'
.Surprisingly, this results in
key=None
behaving as if it were a keyed message and always being sent to a single partition rather than round-robining.This is because the serialization layer is processed before the partitioning logic. So by the time https://github.com/dpkp/kafka-python/blob/1.4.4/kafka/partitioner/default.py#L24 is hit, the key is already the string
'null'
.I found this extremely surprising... at a minimum we need to call this out in the docs.
Alternatively, we could offer default helpers that handle null keys/values (for deleting messages in compacted topics) in a less surprising way.
Related: #913.
The text was updated successfully, but these errors were encountered: