Sending Key Value Messages with the Kafka Console Producer

When working with Kafka you might find yourself using the kafka-console-producer ( 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 parse.key and 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”.

If you haven’t installed Kafka yet, see our Kafka Quickstart Tutorial to get up and running quickly.

4 thoughts on “Sending Key Value Messages with the Kafka Console Producer”

    • Kyle

      Nice tutorial but you spelled “Separator” wrong which causes an error. For anyone who sees this later, that’s what fixes it.

  1. GregB

    You made my day !
    It’s been days I try to use console-producer to send messages in streams and tables, without understanding why the rowkey was null and the tables stayed empty. Now I know why, up to you !
    Thanks so much.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">