Topics store messages created by producers and subscribed by consumers. If automatic topic creation is not enabled during Kafka instance creation, you need to manually create topics. If automatic topic creation has been enabled for the instance, this operation is optional.
Automatic topic creation: A topic will be automatically created when a message is produced in or consumed from a topic that does not exist. By default, the topic has parameters listed in Table 1.
After you change the value of the log.retention.hours, default.replication.factor, or num.partitions parameter, the value will be used in later topics that are automatically created. For example, assume that num.partitions is changed to 5, an automatically created topic has parameters listed in Table 1.
Parameter |
Default Value |
Modified Value |
---|---|---|
Partitions |
3 |
5 |
Replicas |
3 |
3 |
Aging Time (h) |
72 |
72 |
Synchronous Replication |
Disabled |
Disabled |
Synchronous Flushing |
Disabled |
Disabled |
Message Timestamp |
CreateTime |
CreateTime |
Max. Message Size (bytes) |
10,485,760 |
10,485,760 |
Methods that can be used to manually create a topic:
Select the region where your Kafka instance is located.
Parameter |
Description |
---|---|
Topic Name |
Customize a name that contains 3 to 200 characters, starts with a letter or underscore (_), and contains only letters, digits, periods (.), hyphens (-), and underscores (_). The name must be different from preset topics:
Once the topic is created, you cannot modify its name. |
Partitions |
Number of partitions in the topic. If the number of partitions is the same as that of consumers, the larger the partitions, the higher the consumption concurrency. If this parameter is set to 1, messages will be retrieved in the FIFO order. Value range: 1 to 200 Default value: 3 |
Replicas |
A higher number of replicas delivers higher reliability. Data is automatically backed up on each replica. When one Kafka broker becomes faulty, data is still available on other brokers. If this parameter is set to 1, only one set of data is available. Value range: 1 to number of brokers NOTE:
If an instance node is faulty, an internal service error may be reported when you query messages in a topic with only one replica. Therefore, you are not advised using a topic with only one replica. |
Aging Time (h) |
The period that messages are retained for. Consumers must retrieve messages before this period ends. Otherwise, the messages will be deleted and can no longer be consumed. Value range: 1–720 Default value: 72 |
Synchronous Replication |
A message is returned to the client only after the message creation request has been received and the message has been acknowledged by all replicas. After enabling this, set the parameter acks to all or -1 in the configuration file or production code on the producer client. If there is only one replica, synchronous replication cannot be enabled. |
Synchronous Flushing |
|
Message Timestamp |
Timestamp type of a message. Options:
|
Max. Message Size |
Maximum batch processing size allowed by Kafka. If message compression is enabled in the client configuration file or code of producers, this parameter indicates the size after compression. If this is increased and there are consumers older than 0.10.2, the consumers' fetch size must also be increased so that they can fetch record batches this large. Value range: 0 to 10,485,760 |
If your client is v2.2 or later, you can use kafka-topics.sh to create topics and manage topic parameters.
./kafka-topics.sh --create --topic ${topic-name} --bootstrap-server ${connection-address} --partitions ${number-of-partitions} --replication-factor ${number-of-replicas}
./kafka-topics.sh --create --topic ${topic-name} --bootstrap-server ${connection-address} --partitions ${number-of-partitions} --replication-factor ${number-of-replicas} --command-config ./config/ssl-user-config.properties