Get Started Free

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.


1. Prerequisites

This quick start uses the Confluent CLI to run Kafka in Docker. While you won't be running any Docker commands directly, you still need to install and start Docker Desktop or Docker Engine if you don't already have it.

Verify that Docker is set up and running properly by ensuring that no errors are output when you run docker info in your terminal.

2. Install the Confluent CLI

Install the Confluent CLI if you don't already have it. In your terminal:

brew install confluentinc/tap/cli

If you don't use Homebrew, you can use a different installation method.

This quick start requires version 3.18.0 or later of the Confluent CLI. If you have an older version, run confluent update to get the latest release (or brew upgrade confluentinc/tap/cli if you installed the CLI with Homebrew).

3. Start the Kafka broker

Start Kafka by running this command:

confluent local kafka start

This starts Kafka in KRaft combined mode, meaning both the broker and controller run in a single container process.

Combined mode is only appropriate for local development and testing. Please refer to the documentation here for more information on configuring KRaft for production.

4. Create a topic

Create a new topic called quickstart that we'll use to write and read some test messages:

confluent local kafka topic create quickstart

5. Write messages to the topic

You can use the Confluent CLI 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 the following command. You’ll notice that nothing seems to happen, but fear not — it is waiting for your input.

confluent local kafka topic produce quickstart

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

When you’ve finished, enter Ctrl-C 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

6. Read messages from the topic

Now that we’ve written messages to the quickstart topic, we’ll read those messages back with the Confluent CLI:

confluent local kafka topic consume quickstart --from-beginning

As before, this is useful for trying 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

7. Write some more messages

Leave the consume command from the previous step running. If you’ve already closed it, just rerun it.

Now open a new terminal window and run the produce command again:

confluent local kafka topic produce quickstart

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

Enter Ctrl-C in the producer and consumer terminals to exit each client program.

8. Stop the Kafka broker

Once you’ve finished you can shut down Kafka:

confluent local kafka stop

What's Next

  • Build Apps
  • Build Pipelines
  • Operate
Build Apps
  • Build Apps
  • Build Pipelines
  • Operate

Tutorials with Full Code Examples

Learn the basics

Step through the basics of the CLI, Kafka topics, and building applications.

Explore top use cases

Run pre-built ksqlDB recipes that tackle the highest impact use cases for stream processing

Master advanced concepts

Learn how to route events, manipulate streams, aggregate data, and more.

Get Started with Kafka Clients

Write your first application using these full code examples in Java, Python, Go, .NET, Node.js, C/C++, REST, Spring Boot, 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.

Try it for free

Be the first to get updates and new content

We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.