...

/

Consuming and Producing Messages with Keys

Consuming and Producing Messages with Keys

Learn what a Kafka message key is and how to produce and consume messages with keys using the CLI.

We have produced and then consumed messages which only contained values. However, a message can also contain a key. A Kafka message key is usually short compared to the message value and can be of any type we would like, such as a number, a string, etc. We can use message keys if we need related messages to be processed in the same order in which they were received.

Before we begin, let’s create the topic we will work with. Connect to the terminal, and ...