Apache Kafka® Quick Start

The guide below demonstrates how to quickly get started with Apache Kafka. You'll connect to a broker, create a topic, produce some messages, and consume them. Be sure to also check out the client code examples to learn more.


If you want to install Kafka directly then using the Confluent distribution is a good way to do that. You can also use Docker. To try out Kafka as a fully managed service for free check out the Confluent Cloud quick start.

1. Get Apache Kafka

Confluent Platform includes Apache Kafka.

Download the community edition by running this command.

wget https://s3-us-west-2.amazonaws.com/staging-confluent-packages-6.2.0/archive/6.2/confluent-community-6.2.0.tar.gz

Once downloaded, run this command to unpack the tar file

tar -xf confluent-community-6.2.0.tar.gz

For the rest of this quickstart we’ll run commands from the root of the Confluent folder, so switch to it using the cd command

cd confluent-6.2.0

2. Start the Kafka broker

We’ll launch the broker in KRaft mode, which means that it runs without ZooKeeper. Run this command first to configure the storage.

./bin/kafka-storage format \
                    --config ./etc/kafka/kraft/server.properties \
                    --cluster-id $(./bin/kafka-storage random-uuid)

Now you can launch the broker itself by running this command. Don’t close this terminal window as it will shutdown the broker.

./bin/kafka-server-start ./etc/kafka/kraft/server.properties

3. Create a topic

Kafka stores messages in topics. It’s good practice to explicitly create them before using them, even if Kafka is configured to automagically create them when referenced.

Run this command to create a new topic into which we’ll write and read some test messages.

./bin/kafka-topics --bootstrap-server localhost:9092 \
                   --create \
                   --topic quickstart

4. Write messages to the topic

You can use the kafka-console-producer command line tool to write messages to a topic. This is useful for experimentation, but in practice you’ll use the Producer API in your application code, or Kafka Connect for pulling data in from other systems to Kafka.

Run this command. You’ll notice that nothing seems to happen - fear not! It is waiting for your input.

./bin/kafka-console-producer --bootstrap-server localhost:9092 \
                             --topic quickstart

Type in some lines of text. Each line is a new message.

When you’ve finished, press Ctrl-D to return to your command prompt.

this is my first kafka message
hello world!
this is my third kafka message. I’m on a roll :-D

5. Read messages from the topic

Now that we’ve written message to the topic, we’ll read those messages back. Run this command to launch the kafka-console-consumer.

./bin/kafka-console-consumer --bootstrap-server localhost:9092 \
                             --topic quickstart \

As before, this is useful for trialling things on the command line, but in practice you’ll use the Consumer API in your application code, or Kafka Connect for reading data from Kafka to push to other systems.

You’ll see the messages that you entered in the previous step.

this is my first kafka message
hello world!
this is my third kafka message. I’m on a roll :-D

6. Write some more messages

Leave the kafka-console-consumer command from the previous step running. If you’ve already closed it, just re-run it.

Now open a new terminal window and run the kafka-console-producer again.

./bin/kafka-console-producer --bootstrap-server localhost:9092 \
                             --topic quickstart

Enter some more messages and note how they are displayed almost instantaneously in the consumer terminal.

Press Ctrl-D to exit the producer, and Ctrl-C to stop the consumer.

7. Stop the Kafka broker

Once you’ve finished you can shut down the Kafka broker. Press Ctrl-C in the terminal window in which you started the broker.

What's Next

  • Build Apps
  • Build Pipelines
  • Operate
Build Apps
  • Select a value
  • Build Apps
  • Build Pipelines
  • Operate

Get Started with Kafka Clients

Write your first application using these full code examples in Java, Python, Go, .NET, Node.js, C/C++, REST, and further languages and CLIs.

Top 3 Courses for Application Developers

Confluent Cloud is a fully managed Apache Kafka service available on all three major clouds. Try it for free today