Creates a subscription.

Description

You can call this operation to create a subscription. A subscription name can be up to 255 characters in length and contain letters, digits, and hyphens (-). It must start with a letter or digit.

You must specify an endpoint when you create a subscription. Otherwise, the subscription is invalid.

Request

A request consists of the following parts:

  • Request line

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

  • Operation-specific request headers

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

  • Request Body

    The request body is in the XML format. The request body includes the following parameters.

    Parameter Required Description Value
    Endpoint Yes The endpoint that is used to receive messages. QueueEndpoint. Syntax: acs:mns:{REGION}:{AccountID}:queues/{QueueName}.
    FilterTag No The tag that is used to filter messages. Only the messages that have the same tag can be pushed. A tag can be a maximum of 16 characters in length. By default, no tag is specified to filter messages.
    NotifyStrategy No The retry policy that is applied when an error occurs during the push of the message to the endpoint. Valid values: BACKOFF_RETRY and EXPONENTIAL_DECAY_RETRY. Default value: BACKOFF_RETRY. For more information about retry policies, see NotifyStrategy.
    NotifyContentFormat No The format of the message that is pushed to the endpoint. Valid values: XML, JSON, and SIMPLIFIED. Default value: XML. For more information about the format of messages, see NotifyContentFormat.

Response

A response consists of the following parts:

  • HTTP Status Code

    HTTP/1.1 201

    In a topic, each subscription name must be unique. If you create a subscription that already exists, errors may occur. For example, if the parameters of two subscriptions are the same, the HTTP status code 204 is returned. If the parameters of two subscriptions are different, the HTTP status code 409 is returned.

  • Operation-specific response headers
    Parameter Description
    Location The URL of the subscription that is created. Syntax: http://$AccountId.mns.cn-hangzhou.aliyuncs.com/topics/$TopicName/subscriptions/$SubscriptionName.

    For information about common request headers, see Common parameters.

  • Response Body

    None.

Examples

Sample requests

PUT /topics/$TopicName/subscriptions/$SubscriptionName HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Tue, 08 Dec 2015 06:06:46 GMT
Authorization:MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAMPLE=
x-mns-version: 2015-06-06

<? xml version="1.0" encoding="utf-8"? >
<Subscription xmlns="http://mns.aliyuncs.com/doc/v1/">
    <Endpoint>http://company.com</Endpoint>
    <NotifyStrategy>BACKOFF_RETRY</NotifyStrategy>
    <NotifyContentFormat>SIMPLIFIED</NotifyContentFormat>
    <FilterTag>important</FilterTag>
</Subscription>

Sample success responses

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

Special Error

Error code Error message HTTP status code
SubscriptionNameLengthError Subscription name length is out of range, should be between 1 and 255. 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