Search⌘ K
AI Features

Consuming and Producing Messages with Keys

Explore how to produce and consume Kafka messages containing keys to ensure related messages maintain order. Learn key concepts, command options, and how to handle keys in messages using Kafka CLI tools for effective stream processing.

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 ...