Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to you set Kafka producer key to null?

Kafka Producer is forcing the message key to be a string. If I omit in the Message Key field in Kafka Producer, it makes the message key an empty string.

Kafka Brokers treat this as a null, and will evenly distribute messages across partitions. All good there on message distribution across partitions. However, other Confluent tooling is NOT happy with a blank string as key. It is expecting a string or a Null. In particular, the Confluent REST API is very upset with empty string, as it is expecting JSON or Avro key if the value is in those formats, as is Confluent Python library. It handles Null keys fine, as it isn't trying to then parse the string.

Is there a way to force in the MessageKey to be a Null value, instead of blank string? Using blank string is causing unintended consequences in other Kafka tools.