(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
- Method 2: Creating a Topic on Kafka Manager
- Method 3: Create a Topic by Using Kafka CLI
Method 1: Creating a Topic on the Console
- Log in to the Kafka console, and select the region where the Kafka instance is located.
- Click a Kafka instance.
- On the Topics tab page, click Create Topic.
- 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, an underscore (_) or 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, an underscore (_) or 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:
- (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.
- 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
- (Optional) If the SSL certificate configuration has been set, skip this step. Otherwise, perform the following operations:
Follow-Up Procedure
Step 4: Connect to a Kafka Instance to Create and Retrieve Messages
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot