According to the Kafka documentation:
The producer is responsible for choosing which message to assign to which partition within the topic.
By now, the ConsoleProducer
seems to support writing keyed messages to the topic. Kafka will use the hash of the key to distribute the message into partitions, at least with the default behaviour.
Currently, the default separator is \t
, so entering key[\t]message
will distribute it amongst partitions:
key1 a-message
The separator can be changed by providing the key.separator
configuration, for example:
kafka-console-producer --broker-list localhost:9092,localhost:9093 \
--topic mytopic --property key.separator=,
Send messages like this:
key2,another-message
I have tested this with the default tab and a custom seperator successfuly. The messages were distributed to two separate partitions.