tencent cloud

Feedback

CreateTopic

Last updated: 2023-08-09 14:43:18

1. API Description

Domain name for API request: tdmq.tencentcloudapi.com.

This API is used to add a message topic in the specified partition and type.

A maximum of 200 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common Params. The value used for this API: CreateTopic.
Version Yes String Common Params. The value used for this API: 2020-02-17.
Region No String Common Params. This parameter is not required for this API.
EnvironmentId Yes String Environment (namespace) name.
TopicName Yes String Topic name, which can contain up to 64 letters, digits, hyphens, and underscores.
Partitions Yes Integer The value “1” indicates a non-partitioned topic (a topic with no partitions) will be created. A value between 1 (exclusive) and 128 (inclusive) indicates the partition count of a partitioned topic.
Remark No String Remarks (up to 128 characters).
TopicType No Integer This input parameter will be disused soon. You can use PulsarTopicType instead.
0: General message;
1: Globally sequential message;
2: Partitionally sequential message;
3: Retry letter topic;
4: Dead letter topic.
ClusterId No String Pulsar cluster ID
PulsarTopicType No Integer Pulsar topic type.
0: Non-persistent and non-partitioned
1: Non-persistent and partitioned
2: Persistent and non-partitioned
3: Persistent and partitioned

3. Output Parameters

Parameter Name Type Description
EnvironmentId String Environment (namespace) name.
TopicName String Topic name.
Partitions Integer Valid value: 0 or 1. Non-partitioned topic: No partitions. A value greater than 1: The partition count of a partitioned topic. 0 is returned for existing non-partitioned topics, and 1 is returned for incremental non-partitioned topics.
Remark String Remarks (up to 128 characters).
Note: this field may return null, indicating that no valid values can be obtained.
TopicType Integer 0: General message;
1: Globally sequential message;
2: Partitionally sequential message;
3: Retry letter topic;
4: Dead letter topic.
Note: This field may return null, indicating that no valid values can be obtained.
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Creating a topic

This example shows you how to create a topic.

Input Example

POST / HTTP/1.1
Host: tdmq.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: CreateTopic
<Common request parameters>

{
    "EnvironmentId": "default",
    "Remark": "2-partition general message queue",
    "TopicType": "0",
    "TopicName": "test_topic",
    "Partitions": "2"
}

Output Example

{
    "Response": {
        "EnvironmentId": "default",
        "TopicName": "test_topic",
        "Partitions": 2,
        "TopicType": 0,
        "Remark": "2-partition general message queue",
        "RequestId": "d9686bf9-8d7d-4e78-bb44-5140d70a1ffa"
    }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
AuthFailure.UnauthorizedOperation CAM authentication failed.
FailedOperation Operation failed.
FailedOperation.CreateTopic Failed to create the topic.
InternalError.SystemError System error.
InvalidParameterValue The parameter value is incorrect.
InvalidParameterValue.InvalidParams The parameter value is out of the value range.
LimitExceeded.Topics The number of topics under the instance exceeds the limit.
MissingParameter.NeedMoreParams A required parameter is missing.
ResourceInUse The resource is in use.
ResourceInUse.Topic A topic with the same name already exists.
ResourceNotFound.BrokerCluster The service cluster does not exist.
ResourceNotFound.Cluster The cluster does not exist.
ResourceNotFound.Environment The environment does not exist.
ResourceUnavailable.FundRequired You must top up before proceeding.