Create an Apache Kafka® topic
A topic in Aiven for Apache Kafka® is a named stream of messages used by producers to send data and by consumers to read it.
You can configure Aiven for Apache Kafka to automatically create topics when a message is produced to a non-existent topic, but it is recommended to create topics beforehand, especially in production environments.
Manual creation lets you:
- Configure the number of partitions, replication factor, and retention period.
- Avoid accidental topic creation caused by typos or incorrectly configured clients.
If tiered storage is enabled for your Aiven for Apache Kafka® service, all new topics have tiered storage enabled by default. Learn more about tiered storage.
Steps to create an Apache Kafka® topic
- Console
- CLI
- Terraform
-
Log in to the Aiven Console and select the Aiven for Apache Kafka® service to create the topic.
-
Click Topics.
-
Click Create topic.
-
Enter a name for the topic.
-
To configure additional settings, turn on Enable advanced configuration.
-
In the Topic advanced configuration section, configure properties such as the replication factor, number of partitions, and retention settings. You can change these later if needed.
noteThe
message.format.version
configuration is deprecated in Kafka 3.x and removed in Kafka 4.0. Remove this configuration from your topics before upgrading to Kafka 4.0. -
Click Create topic.
You can see the new topic immediately. It may take a few minutes before you can update its settings.
-
Decide on the topic settings, such as the number of partitions, replication factor, and retention period.
-
Run the following command to create a topic named
exampleTopic
:avn service topic-create \
--project demo-kafka-project \
--service-name demo-kafka-service \
--topic exampleTopic \
--partitions 2 \
--replication 2Parameters:
avn service topic-create
: Creates a topic--project demo-kafka-project
: Aiven project name--service-name demo-kafka-service
: Aiven for Apache Kafka® service name--topic exampleTopic
: Name of the topic--partitions 2
: Number of partitions--replication 2
: Replication factor
Use the aiven_kafka_topic
resource to define a topic in your Aiven for Apache Kafka
service.
Loading...
For more details, see the Terraform documentation.
Related pages