閱讀512 返回首頁    go iPhone_iPad_Mac_手機_平板_蘋果apple


Subscription操作__主題接口規範_API使用手冊_消息服務-阿裏雲

描述

該接口用於訂閱主題,創建 Subscription。
Subscription 名稱是一個不超過 256 個字符的字符串,必須以字母或者數字為首字符,剩餘部分可以包含字母、數字和橫華線(-)。
創建Subscription 時,需要指定對應的 Endpoint,否則不合法,目前支持HttpEndpoint。

Request

Request 的構造主要由以下幾部分組成:

  • 請求行

    PUT /topics/$TopicName/subscriptions/$SubscriptionName HTTP/1.1

  • 特有 Request Header

    無,請參考 調用方式/公共參數

  • Request Body

    Request Body 為 XML 格式,XML 總包含創建 Subscription 的屬性。

參數名稱 說明 參數值 選項
Endpoint 描述此次訂閱中接收消息的終端地址 目前三種Endpoint: 1. HttpEndpoint,必須以”https://"為前綴 2. QueueEndpoint, 格式為acs:mns:{REGION}:{AccountID}:queues/{QueueName} 3. MailEndpoint, 格式為mail:directmail:{MailAddress} Required
FilterTag 描述了該訂閱中消息過濾的標簽(標簽一致的消息才會被推送) 不超過16個字符的字符串,默認不進行消息過濾 Optional
NotifyStrategy 描述了向 Endpoint 推送消息出現錯誤時的重試策略 BACKOFF_RETRY 或者 EXPONENTIAL_DECAY_RETRY,默認為BACKOFF_RETRY,重試策略的具體描述請參考 基本概念/NotifyStrategy Optional
NotifyContentFormat 描述了向 Endpoint 推送的消息格式 XML 、JSON 或者 SIMPLIFIED,默認為 XML,消息格式的具體描述請參考 基本概念/NotifyContentFormat Optional

Response

返回消息由返回狀態行、HTTP頭和消息體三部分組成

  • HTTP Status Code

    HTTP/1.1 201
    同一個訂閱者在同一個主題下的 Subscription 不能重名,當出現重名時,如果正在創建的 Subscription 已經存在的 Subscription 屬性完全相同,返回 204,否則返回 409 (Conflict)。

  • 特有 Response Header

參數名稱 說明
Location 返回創建成功的 SubscriptionURL,格式如下:https://$AccountId.mns.cn-hangzhou.aliyuncs.com/topics/$TopicName/subscriptions/$SubscriptionName

其它 Response Header 請參考 調用方式/公共參數

  • Response Body

Special Error

錯誤代碼 錯誤信息 狀態碼
SubscriptionNameLengthError Subscription name length is out of range, should be between 1 and 256. 400
SubscriptionNameInvalid The subscription you provided is invalid. SubscriptionName should start with alpha or digit, and contain only alpha, digit or -. 400
SubscriptionAlreadyExist The subscription you want to create already exists. 409
EndpointInvalid The endpoint you provided is invalid. 400
InvalidArgument The length of filter tag should be between 1 and 16. 400

請求示例:

  1. PUT /topics/$TopicName/subscriptions/$SubscriptionName HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Tue, 08 Dec 2015 06:06:46 GMT
  4. Authorization:MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE=
  5. x-mns-version: 2015-06-06
  6. <?xml version="1.0" encoding="utf-8"?>
  7. <Subscription xmlns="https://mns.aliyuncs.com/doc/v1/">
  8. <Endpoint>https://company.com</Endpoint>
  9. <NotifyStrategy>BACKOFF_RETRY</NotifyStrategy>
  10. <NotifyContentFormat>SIMPLIFIED</NotifyContentFormat>
  11. <FilterTag>important</FilterTag>
  12. </Subscription>

返回示例:

  1. HTTP/1.1 201
  2. x-mns-request-id:56667376B2B71C9C16000025
  3. x-mns-version: 2015-06-06
  4. Location: https://$AccountId.mns.cn-hangzhou.aliyuncs.com/topics/$TopicName/subscriptions/$SubscriptionName

SetSubscriptionAttributes

描述

該接口用於修改 Subscription 的屬性

Request

Request 的構造主要由以下幾個部分組成:

  • 請求行

    PUT /topics/$TopicName/subscriptions/$SubscriptionName?metaoverride=true HTTP/1.1

  • 特有 URI 參數

    metaoverride=true 將會修改 Subscription 的屬性

  • 特有 Request Header

    無,請參考 調用方式/公共參數

  • Request Body

    Request Body 為 XML 格式,XML 中包含修改 Subscription 的屬性:

參數名稱 說明 參數值 選項
NotifyStrategy 描述了向 Endpoint 推送消息出現錯誤時的重試策略 BACKOFF_RETRY 或者 EXPONENTIAL_DECAY_RETRY,默認為BACKOFF_RETRY,重試策略的具體描述請參考 基本概念/NotifyStrategy Optional

Response

返回消息由返回狀態行、HTTP頭和消息體三部分

  • HTTP Status Code

    HTTP/1.1 204 No Content

  • 特有 Response Header

    無,請參考 調用方式/公共參數

  • Response Body

Special Error:

錯誤代碼 錯誤消息 狀態碼
SubscriptionNotExist The subscription you provided does not exits. 404

請求示例:

  1. PUT /topics/$TopicName/subscriptions/$SubscriptionName?metaoverride=true HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Tue, 08 Dec 2015 06:09:22 GMT
  4. Authorization: MNS 15B4D3461F177624206A:rNT4xclLS297/n0UFYIezzHJI7Q=
  5. x-mns-version: 2015-06-06
  6. <?xml version="1.0" encoding="utf-8"?>
  7. <Subscription xmlns="https://mns.aliyuncs.com/doc/v1/">
  8. <NotifyStrategy>BACKOFF_RETRY</ NotifyStrategy>
  9. </Subscription>

返回示例:

  1. HTTP/1.1 204 No Content
  2. x-mns-request-id:56667412B2B71C9C16000027
  3. x-mns-version: 2015-06-06

GetSubscriptionAttributes

描述

該接口用於獲取 Subscription 的屬性

Request

Request 的構造主要由以下幾個部分組成:

  • 請求行

    GET /topics/$TopicName/subscriptions/$SubscriptionName HTTP/1.1

  • 特有 Request Header

    無,請參考 調用方式/公共參數

  • Request Body

Response

返回消息由返回狀態行、HTTP頭和消息三部分組成

  • HTTP Status Code

    HTTP/1.1 200 OK

  • 特有 Response Header

    無,請參考 調用方式/公共參數

  • Response Body

參數名稱 說明
SubscriptionName Subscription 的名稱
Subscriber Subscription 訂閱者的 AccountId
TopicOwner Subscription 訂閱的主題所有者的 AccountId
TopicName Subscription 訂閱的主題名稱
Endpoint 訂閱的終端地址
NotifyStrategy 向 Endpoint 推送消息錯誤時的重試策略
NotifyContentFormat 向 Endpoint 推送的消息內容格式
FilterTag 描述了該訂閱中消息過濾的標簽(僅標簽一致的消息才會被推送)
CreateTime Subscription 的創建時間,從 1970-1-1 00:00:00 到現在的秒值
LastModifyTime 修改 Subscription 屬性信息最近時間,從 1970-1-1 00:00:00 到現在的秒值

Special Error

錯誤代碼 錯誤信息 狀態碼
SubscriberNotExist The subscription you provided does not exist. 404

請求示例:

  1. GET /topics/$TopicName/subscriptions/$SubscriptionName HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Tue, 08 Dec 2015 06:09:58 GMT
  4. Authorization: MNS 15B4D3461F177624206A:GvaApggLQfMu6B6W5sbF6HEjV6Y=
  5. x-mns-version: 2015-06-06

返回示例:

  1. HTTP/1.1 200 OK
  2. Content-Type=text/xml;utf-8
  3. Content-Length:451
  4. x-mns-request-id:56667436B2B71C9C16000029
  5. x-mns-version: 2015-06-06
  6. <?xml version="1.0" encoding="utf-8"?>
  7. <Subscription xmlns="https://mns.aliyuncs.com/doc/v1">
  8. <CreateTime>1449554806</CreateTime>
  9. <Endpoint>https://company.com</Endpoint>
  10. <FilterTag>important</FilterTag>
  11. <LastModifyTime>1449554962</LastModifyTime>
  12. <NotifyContentFormat>XML</NotifyContentFormat>
  13. <NotifyStrategy>BACKOFF_RETRY</NotifyStrategy>
  14. <SubscriptionName>$SubscriptionName</SubscriptionName>
  15. <Subscriber>$Subscriber</Subscriber>
  16. <TopicName>$TopicName</TopicName>
  17. <TopicOwner>$TopicOwner</TopicOwner>
  18. </Subscription>

Unsubscribe

描述

該接口用於取消一個已創建的 Subscription。

Request

Request 的構造主要由以下幾個部分組成:

  • 請求行

    DELETE /topics/$TopicName/subscriptions/$SubscriptionName HTTP/1.1

  • 特有 Request Header

    無,請參考 調用方式/公共參數

  • Request Body

Response

返回消息由返回狀態行、HTTP頭和消息體三部分組成

  • HTTP Status Code

    HTTP/1.1 204 No Content
    如果 Unsubscribe 的 Subscription 不存在,返回 204,取消訂閱成功

  • 特有 Response Header

    無,請參考 調用方式/公共參數

  • Response Body

請求示例:

  1. DELETE /topics/$TopicName/Subscriptions/$SubscriptionName HTTP/1.1
  2. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  3. Date: Tue, 08 Dec 2015 06:18:04 GMT
  4. Authorization: MNS 15B4D3461F177624206A:UOEb7OmC9GX7G9BLY3XryP6vtjQ=
  5. x-mns-version: 2015-06-06

返回示例:

  1. HTTP/1.1 204 No Content
  2. x-mns-request-id: 5666761CB2B71C9C16000035
  3. x-mns-version: 2015-06-06

ListSubscriptionByTopic

描述

該接口用於列出某個主題下的 Subscription 列表,可分頁獲取數據。

Tips:

如果本次請求結果返回的 Subscription 總數超過本次請求的 x-mns-ret-number 參數值,返回的 XML 結果中包含的 NextMarker 表示下一頁開始位置,在下一次請求時將該值賦予 x-mns-marker 參數以返回下一頁的結果。

Request

Request 的構造主要由以下幾個部分組成:

  • 請求行

    GET /topics/$TopicName/subscriptions HTTP/1.1

  • 特有 Request Header

參數名稱 說明 選項
x-mns-prefix 按照該前綴開頭的 SubscriptionName 進行查找 Optional
x-mns-marker 請求下一個分頁的開始位置,從上次分頁結果返回的 NextMarker 獲取 Optional
x-mns-ret-number 單次請求結果的最大返回個數,1 - 1000 範圍內的整數值,默認值為 1000 Optional

其它 Request Header 請參考 調用方式/公共參數

  • Request Body

Response

返回消息由返回狀態行、HTTP頭和消息體三部分組成

  • HTTP Status Code

    HTTP/1.1 200 OK

  • 特有 Response Header

    無,請參考 調用方式/公共參數

  • Response Body

    返回 XML 格式的結果,頂層 Subscriptions 元素下包含多個 Subscription 元素,Subscription 元素中包含 SubscriptionURL,SubscriptionURL 表示 Subscription 的 URL 訪問地址。如果返回結果超過 x-mns-ret-number 的參數值,包含 NextMarker 元素表示下個分頁的起始位置。

請求示例:

  1. GET /topics/$TopicName/subscriptions HTTP/1.1
  2. x-mns-ret-number:2
  3. Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
  4. Date: Tue, 08 Dec 2015 06:16:18 GMT
  5. Authorization: MNS 15B4D3461F177624206A:dXSLY5yGG8Ri5f26ZEmxMCq1CC4=
  6. x-mns-version: 2015-06-06

返回示例:

  1. HTTP/1.1 200 OK
  2. x-mns-request-id:566675B2B2B71C9C16000033
  3. x-mns-version: 2015-06-06
  4. <?xml version="1.0" encoding="utf-8"?>
  5. <Subscriptions xmlns="https://mns.aliyuncs.com/doc/v1/">
  6. <Subscription>
  7. <SubscriptionURL>https://$AccountId.mns.cn-hangzhou.aliyuncs.com/$TopicName/subscriptions/$SubscriptionName1</SubscriptionURL>
  8. </Subscription>
  9. <Subscription>
  10. <SubscriptionURL>https://$AccountId.mns.cn-hangzhou.aliyuncs.com/$TopicName/subscriptions/$SubscriptionName2</SubscriptionURL>
  11. </Subscription>
  12. <NextMarker>OTczNjU4MTcvYmRwejd6NXluby8yNjg0Mi9+fn5FI1Rlc3RUb3BpYy0xI2JkcHo3ejV5bm8jVGVzdFN1Yi0zLzA=</NextMarker>
  13. </Subscriptions>

最後更新:2016-11-23 17:16:04

  上一篇:go Topic操作__主題接口規範_API使用手冊_消息服務-阿裏雲
  下一篇:go Message操作__主題接口規範_API使用手冊_消息服務-阿裏雲