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.
First sign up for a free Confluent Cloud account. You will get $400 in credits when you sign up. To avoid having to enter a credit card, navigate to Billing & payment, scroll to the bottom, and add the promo code CONFLUENTDEV1. With this promo code, you will not have to enter your credit card info for 30 days or until your credits run out.
Next, install the Confluent CLI by navigating to a directory in which to install it and running:
curl -sL --http1.1 https://cnfl.io/cli | sh -s -- latest
Then after installing the CLI log into your Confluent Cloud account by running the following:
confluent login --prompt --save
Create a Basic Kafka cluster by entering the following command, where <provider> is one of aws, azure, or gcp, and <region> is a region ID available in the cloud provider you choose. You can view the available regions for a given cloud provider by running confluent kafka region list --cloud <provider>.
confluent kafka cluster create quickstart --cloud <provider> --region <region>
For example:
confluent kafka cluster create quickstart --cloud aws --region us-east-1
confluent kafka cluster create quickstart --cloud azure --region eastus
confluent kafka cluster create quickstart --cloud gcp --region us-east1
It may take a few minutes for the cluster to be created. Validate that the cluster is running by ensuring that its Status is Up when you run the following command:
confluent kafka cluster list
For example:
confluent kafka cluster list
Id | Name | Type | Provider | Region | Availability | Status
---------------+------------+-------+----------+-------------+--------------+---------
lkc-123456 | quickstart | BASIC | gcp | us-east1 | single-zone | UP
Make your cluster active in the CLI so that you don't need to specify it in later commands:
confluent kafka cluster use <cluster ID>
For example:
confluent kafka cluster use lkc-123456
Set Kafka cluster "lkc-123456" as the active cluster for environment "env-123456".
Create a topic named quickstart that has 1 partition:
confluent kafka topic create quickstart --partitions 1
Create an API key for the cluster that you will use to produce and consume messages:
confluent api-key create --resource <cluster ID>
Then set it as the active API key so that you don't need to specify the API key and secret on the command line when producing and consuming messages:
confluent api-key use <API key> --resource <cluster ID>
Produce a message to the quickstart topic:
confluent kafka topic produce quickstart
Enter the message hello world and then enter Ctrl-C or Ctrl-D to exit:
Starting Kafka Producer. Use Ctrl-C or Ctrl-D to exit.
hello world
^C
Now consume the message that you just produced:
confluent kafka topic consume quickstart --from-beginning
Step through the basics of the CLI, Kafka topics, and building applications.
Learn how to route events, manipulate streams, aggregate data, and more.
Produce to and consume from Kafka in your preferred programming language.
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.
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.