When working with Kafka you might find yourself using the
kafka-console-producer (kafka-console-producer.sh). The
kafka-console-producer is a program included with Kafka that creates messages from command line input (STDIN).
However, simply sending lines of text will result in messages with
null keys. In order to send messages with both keys and values you must set the
key.separator properties on the command line when running the producer.
The below example sets the
parse.key property to
true, and specifies the
key.separator as “
:“. The keys in the sample messages below are “key1”, “key2”, “key3”, with the values being “value1”, “value2”, “value3”.
--broker-list localhost:9092 \
--topic my-topic \
--property "parse.key=true" \
If you haven’t installed Kafka yet, see our Kafka Quickstart Tutorial to get up and running quickly.