Updated on 2023-05-31 GMT+08:00

(Optional) Step 3: Create a Topic

A topic is a stream of messages. If automatic topic creation is not enabled during Kafka instance creation, you need to manually create topics for creating and retrieving messages. If automatic topic creation is enabled, this step is optional. The system automatically creates a topic when a message is created. This topic has the following default settings: 3 partitions, 3 replicas, aging time 72 hours, and synchronous replication and flushing disabled.

The following describes three methods to manually create a topic.

Method 1: Creating a Topic on the Console

  1. Log in to the Kafka console, and select the region where the Kafka instance is located.
  2. Click a Kafka instance.
  3. On the Topics tab page, click Create Topic.
  4. Enter the topic name, specify other parameters, and click OK.

Method 2: Creating a Topic on Kafka Manager

Log in to Kafka Manager, choose Topic > Create, and set parameters as prompted.

If a topic name starts with a special character, for example, a number sign (#), monitoring data cannot be displayed.

Method 3: Create a Topic by Using Kafka CLI

If your client is v2.2 or later, you can use kafka-topics.sh to create topics and manage topic parameters.

If a topic name starts with a special character, for example, a number sign (#), monitoring data cannot be displayed.

  • If SASL is not enabled for the Kafka instance, run the following command in the /{directory where the CLI is located}/kafka_{version}/bin/ directory to create a topic:
    ./kafka-topics.sh --create --topic {topic_name} --bootstrap-server {broker_ip}:{port} --partitions {partition_num} --replication-factor {replication_num}
  • If SASL has been enabled for the Kafka instance, perform the following steps to create a topic:
    1. (Optional) If the SSL certificate configuration has been set, skip this step. Otherwise, perform the following operations:

      Create the ssl-user-config.properties file in the /config directory of the Kafka client and add the SSL certificate configurations by referring to Connecting to an Instance with SASL.

    2. Run the following command in the /{directory where the CLI is located}/kafka_{version}/bin/ directory to create a topic:
      ./kafka-topics.sh --create --topic {topic_name} --bootstrap-server {broker_ip}:{port} --partitions {partition_num} --replication-factor {replication_num} --command-config ./config/ssl-user-config.properties