调用GetTopicAttributes接口获取主题的属性。返回属性除创建主题时的可设置属性外,还可以获取主题的消息最长存活时间、主题创建时间等。

授权信息

默认仅限阿里云账号使用本接口,RAM用户只有在被授予了相关API操作权限后方可使用。本接口的授权信息如下表所示。更多信息,请参见授权策略和示例

Name Value
API GetTopicAttributes
RAM授权操作 mns:GetTopicAttributes
资源 acs:mns:$region:$accountid:/topics/$topicName

请求消息

请求消息由请求行、HTTP头和消息体三部分组成:

  • 请求行

    GET /topics/$TopicName HTTP/1.1

  • 特有Request Header

    无。

  • Request Body

    无。

返回消息

返回消息由返回状态行、HTTP头和消息体三部分组成:

  • HTTP Status Code

    HTTP/1.1 200 OK

  • 特有Response Header

    无。

  • Response Body

    Response Body返回的结果为XML格式,格式为:<TopicAttributes>Attribute Element List</TopicAttributes>

    属性元素列表包括以下参数。

    参数名称 类型 示例值 描述
    TopicName String demo-topic 主题的名称。
    CreateTime Long 1449554277 主题的创建时间,从1970-01-01 00:00:00到现在的时间。
    LastModifyTime Long 1449554460 修改主题属性信息的最近时间,从1970-01-01 00:00:00到现在的时间。
    MaximumMessageSize Integer 65536 发送到该主题的消息体最大长度,单位为Byte。
    MessageRetentionPeriod Integer 86400 消息在主题中最长存活时间,从发送到该主题开始经过此参数指定的时间后,不论消息是否被成功推送给用户都将被删除,单位为秒。
    MessageCount Integer 0 当前该主题中消息数目。
    LoggingEnabled Boolean True 是否开启日志管理功能,取值说明如下:
    • True:启用。
    • False:停用。

示例

请求示例:

GET /topics/$TopicName HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Tue, 08 Dec 2015 06:02:33 GMT
x-mns-version: 2015-06-06
Authorization:MNS 15B4D3461F177624206A:aVZgLZzVchjOtM1aecDQYFuj****

返回示例:

HTTP/1.1 200 OK
Content-Type=text/xml;utf-8
Content-Length:145
x-mns-request-id:56667279B2B71C9C1600****
x-mns-version: 2015-06-06

<?xml version="1.0" encoding="UTF-8"?>
<Topic xmlns=http://mns.aliyuncs.com/doc/v1/”>
    <TopicName>demo-topic</TopicName>
    <CreateTime>1449554277</CreateTime >
    <LastModifyTime>1449554460</LastModifyTime>
    <MaximumMessageSize>65536</MaximumMessageSize>
    <MessageRetentionPeriod>86400</MessageRetentionPeriod>
    <MessageCount>0</MessageCount>
    <LoggingEnabled>True</LoggingEnabled>
</Topic>     

错误码

错误码 错误消息 HTTP状态码 描述内容
TopicNotExist The topic you provided does not exist. 404 队列不存在,请先创建队列。