Creating a Topic
Function
This API is used to create a topic.
URI
POST /v2/{project_id}/mqs/instances/{instance_id}/topics
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Project ID. For details about how to obtain a project ID, see "Appendix" > "Obtaining a Project ID" in this document. |
| instance_id | Yes | String | Instance ID. |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | User token, which can be obtained by calling the IAM API (value of X-Subject-Token in the response header). |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | Yes | String | Topic name, which must start with a letter and contains 3 to 200 characters. Only digits, letters, underscores (_), and hyphens (-) are allowed. |
| app_id | Yes | String | Integration application key. |
| app_key | No | String | Integration application key. |
| partition | No | Integer | Number of topic partitions, which is used to set the number of concurrently consumed messages. Value range: 1 to 100. Default value: 3. |
| replication | No | Integer | Number of replicas, which is configured to ensure data reliability. Value range: 1 to 3. Default: 3. |
| access_policy | Yes | String | Permission type. |
| sync_message_flush | No | Boolean | Whether synchronous flushing is enabled. The default value is false. Synchronous flushing compromises performance. |
| sync_replication | No | Boolean | Whether synchronous replication is enabled. After this function is enabled, the acks parameter on the producer client must be set to –1. Otherwise, this parameter does not take effect. |
| retention_time | No | Integer | Message retention period. The default value is 72. Value range: 1 to 168, in hours |
| tag | No | String | Tag corresponding to the permission type. When the permission type is all, publish and subscribe tags are separated by ampersands (&). Multiple tags are separated by double vertical bars (||). |
| description | No | String | Description. Length: 0 to 1,000 characters. The value cannot begin with an equals sign (=), plus sign (+), hyphen (-), or at sign (@). |
| sensitive_word | No | String | Sensitive word. Multiple sensitive words are separated by double vertical bars (||). |
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| name | String | Topic name. |
Status code: 400
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Error code. |
| error_msg | String | Error message. |
Example Requests
Create a topic with 3 partitions and 3 replicas and set the message retention period to 72 hours.
POST https://{endpoint}/v2/{project_id}/mqs/instances/{instance_id}/topics
{
"name" : "topic-test-2",
"app_id" : "c5abd910-02b1-4bc4-b587-c3fe4c49dab9",
"partition" : 3,
"access_policy" : "all",
"replication" : 3,
"retention_time" : 72,
"sync_replication" : false,
"sync_message_flush" : false,
"tag" : "11 || 22 || aa || bb&11 || 22 || aa || bb",
"description" : "test",
"sensitive_word" : "sss || ddd"
} Example Responses
Status code: 200
OK
{
"name" : "topic-mqs-test"
} Status code: 400
Bad Request
{
"error_code" : 400,
"error_msg" : "Bad Request"
} Status code: 403
Forbidden
{
"error_code" : 403,
"error_msg" : "Forbidden"
} Status Codes
| Status Code | Description |
|---|---|
| 200 | OK |
| 400 | Bad Request |
| 403 | Forbidden |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.