Creates a queue.

Authorization

By default, only Alibaba Cloud accounts can call this operation. RAM users can call this operation only after these RAM users are granted related permissions. The following table describes the authorization information of this operation. For more information, see Permission policies and examples.

Item Value
API operation CreateQueue
Action mns:CreateQueue
Resource acs:mns:$region:$accountid:/queues/$queueName

Description

  • The name of a queue is a string that can be a maximum of 120 characters in length and can contain letters, digits, and hyphens (-). The name must start with a letter or digit.
  • You can create a maximum of 1,000 queues. If you need to extend the limit, submit a ticket.

Request

A request consists of the following parts:

  • Request line

    PUT /queues/$queueName HTTP/1.1

  • Operation-specific request headers

    None.

  • Request Body

    The request body is in the XML format. The request body includes the parameters that are used to create a queue. The parameters are optional.

    Parameters

    Parameter Type Required Example Description
    DelaySeconds Integer No. 0 The waiting period after which all messages sent to the queue can be consumed.

    Valid values: 0 to 604800. Unit: seconds.

    Default value: 0.

    MaximumMessageSize Integer No. 65536 The maximum size of the message body that can be sent to the queue.

    Valid values: 1024 to 65536. Unit: bytes.

    Default value: 65536.

    MessageRetentionPeriod Integer No. 345600 The maximum period of time for which a message can be retained in the queue. A message that is sent to the queue can be retained for a specified period of time. After the specified period ends, the message is deleted regardless of whether the message is consumed.

    Valid values: 60 to 604800. Unit: seconds.

    Default value: 345600.

    VisibilityTimeout Integer No. 60 The invisibility period for which the received message remains in the Inactive state.

    Valid values: 1 to 43200. Unit: seconds.

    Default value: 30.

    PollingWaitSeconds Integer No. 0 The maximum period for which a ReceiveMessage request waits if no message is available in the queue.

    Valid values: 0 to 30. Unit: seconds.

    Default value: 0.

    LoggingEnabled Boolean No True Specifies whether to enable the log management feature for the queue. Valid values:
    Valid values:
    • True: enables the feature.
    • False: disables the feature.
    Default value: False.
    Note
    • If you configure the PollingWaitSeconds parameter for a queue and no message is available in the queue, MNS holds each (Batch)ReceiveMessage request for long polling. If no message is sent to the queue within the period that is specified by the PollingWaitSeconds parameter, the MessageNotExist error message is returned. If a message is sent to the queue during the specified period of time, the message is returned to the consumer client.
    • We recommend that you reduce the number of concurrent long polling requests. MNS determines the maximum number of concurrent long polling requests based on the number of requests, the waiting period of requests, and the number of IP addresses. If the limit is exceeded, MNS does not hold the request and returns the 404MessageNotExist error. In this case, you are charged based on the number of requests. If you want to increase the limit to prevent excessive costs, submit a ticket.
    • If you want to use Terraform to manage alicloud_message_service_queue, configure the EnableLogging parameter instead of the LoggingEnabled parameter in the request body.

Response

A response consists of the following parts:

  • HTTP status code

    HTTP/1.1 201 Created

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

  • Operation-specific response headers
    Parameter Type  Example Description
    Location String http://$AccountId.mns.cn-hangzhou.aliyuncs.com/queues/$queueName The URL of the queue that was created. Syntax: http://$AccountId.mns.<Region>.aliyuncs.com/queues/$queueName.
  • Response body

    None.

Examples

Sample requests

PUT  /queues/$queueName HTTP/1.1
Host: $AccountId.mns.cn-hangzhou.aliyuncs.com
Date: Wed, 08 Mar 2012 12:00:00 GMT
x-mns-version: 2015-06-06
Authorization:MNS 15B4D3461F177624206A:xQE0diMbLRepdf3YB+FIEXAM****

<?xml version="1.0" encoding="UTF-8"?>
<Queue xmlns="http://mns.aliyuncs.com/doc/v1/">
    <VisibilityTimeout>60</VisibilityTimeout>
    <MaximumMessageSize>65536</MaximumMessageSize>
    <MessageRetentionPeriod>345600</MessageRetentionPeriod>
    <LoggingEnabled>True</LoggingEnabled>
</Queue>            

Sample success responses

HTTP/1.1 201 Created
x-mns-request-id:512B2A634403E52B1956****
x-mns-version: 2015-06-06
Location: http://$AccountId.mns.cn-hangzhou.aliyuncs.com/queues/$queueName         

Error codes

Error code Error message HTTP status code Description
QueueAlreadyExist The queue you want to create is already exist. 409 The error message returned because the specified queue has the same name as an existing queue, but has different parameters from the existing queue.
InvalidArgument The value of Element should between Low and High seconds/bytes. 400 The error message returned because the length of the tag is invalid. You must modify the tag.
QueueNumExceededLimit The number of the queues you created has excceeded the limit. 400 The error message returned because the number of created queues exceeds the limit 1,000.