Create an Apache Kafka® topic
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.
This approach offers several advantages:
- You can define specific topic settings, such as the number of partitions, replication factor, retention period, and more.
- It helps prevent the creation of incorrect topics due to typos or other mistakes.
note
When tiered storage is activated for your Aiven for Apache Kafka service, all new topics will have tiered storage enabled by default. Learn more about tiered storage.
Steps to create an Apache Kafka® topic
- Console
- CLI
- Log in to the Aiven Console and select the Aiven for Apache Kafka® service to create the topic.
- Click Topics in the sidebar.
- Click Create topic and enter a name for the topic.
- If required, set the advanced configuration option to Yes.
- In the Topic advanced configuration section, set properties such as the replication factor, number of partitions, and other settings. These settings can be modified later.
- Click Create topic.
The new topic is visible immediately, but it may take a few minutes before you can update its settings.
-
Determine the topic specifications, including the number of partitions, replication factor, and other settings.
-
Run the following command to create the
exampleTopic
topic: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
: Specifies the project name.--service-name demo-kafka-service
: Specifies the Aiven for Apache Kafka® service name.--topic exampleTopic
: Specifies the name of the topic to create.--partitions 2
: Specifies the number of partitions for the topic.--replication 2
: Specifies the replication factor for the topic.