Creates a topic.

Description

You can call this operation to create a topic.

The name of the topic is a string that can be a maximum of 255 characters in length and can contain letters, digits, and hyphens (-). It must start with a letter or digit.

Request

Each request consists of the following parts:

  • Request line

    PUT /topics/$TopicName HTTP/1.1

  • Operation-specific request headers

    None. For more information about common request headers, see Common parameters.

  • Request Body

    The request body is in the XML format. It contains the following parameters that are used to create a topic.

    Parameter Required Description Value
    MaximumMessageSize No The maximum size of the message body. Unit: bytes. Valid values: 1024 B (1 KB) to 65536 B (64 KB). Data type: integer. Default value: 65536 B (64 KB).
    LoggingEnabled No Indicates whether the log management feature is enabled for the queue. Valid values:
    • True: The log management feature is enabled.
    • False: The log management feature is disabled.
    Default value: False.

Response

Each response consists of the following parts:

  • HTTP Status Code

    HTTP/1.1 201 Created

    The name of each topic must be unique in a region within an Alibaba Cloud account. If you create a topic whose name already exists, errors may occur. For example, if the parameters of the two topics are the same, the error code 204 (No Content) is returned. If the parameters of the two topics are different, the error code 409 (Conflict) is returned.

  • Operation-specific response headers
    Parameter Description
    Location The URL of the topic that was created. Syntax: http://$AccountId.mns. <Region>.aliyuncs.com/topics/$TopicName.

    For more information about other response headers, see Common parameters.

  • Response Body

    None.

Examples

Sample requests

PUT /topics/$TopicName HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Tue, 08 Dec 2015 05:57:57 GMT
x-mns-version: 2015-06-06
Authorization:MNS 15B4D3461F177624206A:eCtaUwfGS0oEfznzJEhWFxpf2yk=

<? xml version="1.0" encoding="utf-8"? >
<Topic xmlns="http://mns.aliyuncs.com/doc/v1/">
    <MaximumMessageSize>10240</MaximumMessageSize>
    <LoggingEnabled>True</LoggingEnabled>
</Topic>
            

Sample success responses

HTTP/1.1 201 Created
x-mns-request-id:56667165B2B71C9C16000013
x-mns-version: 2015-06-06
Location: http://$AccountId.mns.cn-hangzhou.aliyuncs.com/topics/$TopicName
            

Special error

Error code Error message HTTP status code
TopicAlreadyExist The topic you want to create is already exists. 409
TopicNameLengthError Topic name length is out of range, should be between 1 and 255. 400