Creates a topic.

  • You can send a maximum of one query per second (QPS).
  • The maximum number of topics that can be created on an instance depends on the specifications of the instance.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateTopic

The operation that you want to perform. Set the value to CreateTopic.

InstanceId String Yes alikafka_pre-cn-mp919o4v****

The ID of the Message Queue for Apache Kafka instance on which you want to create the topic.

Topic String Yes alikafka_topic_test

The name of the topic.

  • The name can contain only letters, digits, hyphens (-), and underscores (_).
  • The name must be 3 to 64 characters in length. Names that contain more than 64 characters are automatically truncated.
  • The name cannot be modified after the topic is created.
Remark String Yes alikafka_topic_test

The description of the topic.

  • The description can contain only letters, digits, hyphens (-), and underscores (_).
  • The description must be 3 to 64 characters in length.
RegionId String Yes cn-hangzhou

The region ID of the Message Queue for Apache Kafka instance.

CompactTopic Boolean No false

The log cleanup policy for the topic. This parameter is available when the Local Storage mode is specified for the topic. Valid values:

  • false: uses the default log cleanup policy.
  • true: uses the Apache Kafka log compaction policy.
PartitionNum String No 12

The number of partitions in the topic.

  • Valid values: 1 to 360.
  • To reduce the risk of data skew, we recommend that you set the number of partitions to a multiple of 6.
  • If you require more than 360 partitions, submit a ticket.
LocalTopic Boolean No false

The storage engine of the topic. Valid values:

  • false: the Cloud Storage mode.
  • true: the Local Storage mode.
ReplicationFactor Long No 3

The number of replicas of the topic.

  • This parameter is available only when the LocalTopic parameter is set to true.
  • Valid values: 1 to 3.
Note If you set this parameter to 1, the risk of data loss increases. Proceed with caution.
MinInsyncReplicas Long No 1

The minimum number of in-sync replicas.

  • This parameter is available only when the LocalTopic parameter is set to true.
  • The value of this parameter must be less than the value of the ReplicationFactor parameter.
  • Valid values: 1 to 3.
Config Map No null

Additional configurations.

  • The value of this parameter must be in the JSON format.
  • The key must be replications. The value specifies the number of replicas of the topic. It must be an integer ranging from 1 to 3.
  • This parameter is available only when the LocalTopic parameter is set to true.
Note If you set this parameter to specify the number of replicas of the topic, the ReplicationFactor parameter no longer takes effect.

Response parameters

Parameter Type Example Description
Code Integer 200

The HTTP status code. The HTTP status code 200 indicates that the request is successful.

Message String operation success

The returned message.

RequestId String 9C0F207C-77A6-43E5-991C-9D98510A****

The ID of the request.

Success Boolean true

Indicates whether the request is successful.

Examples

Sample requests

http(s)://[Endpoint]/?Action=CreateTopic
&InstanceId=alikafka_pre-cn-mp919o4v****
&RegionId=cn-hangzhou
&Remark=alikafka_topic_test
&Topic=alikafka_topic_test
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateTopicResponse>
    <RequestId>9C0F207C-77A6-43E5-991C-9D98510A****</RequestId>
    <Message>operation success</Message>
    <Code>200</Code>
    <Success>true</Success>
</CreateTopicResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "9C0F207C-77A6-43E5-991C-9D98510A****",
  "Message" : "operation success",
  "Code" : 200,
  "Success" : true
}

Error codes

For a list of error codes, visit the API Error Center.