ALIYUN::MNS::Queue

ALIYUN::MNS::Queue类型是消息存储的目的地,队列可以分成普通队列和延时队列两类。

如果发送消息时不指定消息延时参数,被发送到普通队列的消息可以立刻被消费,而发送到延时队列的消息需要经过设定的延时时间后才能被消费。

语法

{
  "Type": "ALIYUN::MNS::Queue",
  "Properties": {
    "PollingWaitSeconds": Integer,
    "LoggingEnabled": Boolean,
    "MessageRetentionPeriod": Integer,
    "MaximumMessageSize": Integer,
    "DelaySeconds": Integer,
    "VisibilityTimeout": Integer,
    "QueueName": String,
    "DlqPolicy": Map,
    "Tags": List
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

QueueName

String

队列名称。

同一账号同一地域, 队列名称不能重复。

长度不超过256个字符,必须以英文字母或数字开头,可包含英文字母、数字和短划线(-)。

DelaySeconds

Integer

发送到该队列的所有消息默认以DelaySeconds参数指定的秒数延后。

取值范围:0~604,800(7天)。

单位:秒。

默认值:0。

MaximumMessageSize

Integer

发送到该队列消息体的最大长度。

取值范围:1024(1KB)~65,536(64KB)。

单位:byte。

默认值:65,536(64KB)。

MessageRetentionPeriod

Integer

消息在该队列中最长的存活时间,从发送到该队列开始经过此参数指定的时间后,不论消息是否被取出过都将被删除。

取值范围:60(1分钟)~604,800(7 天) 。

单位:秒。

默认值:345,600(4 天)。

VisibilityTimeout

Integer

消息从该队列中取出后从Active状态变成Inactive状态后的持续时间。

取值范围:1~43,200(12小时) 。

单位:秒。

默认值:30。

PollingWaitSeconds

Integer

当队列中没有消息时,针对该队列的ReceiveMessage请求最长的等待时间。

取值范围:0~30。

单位:秒。

默认值:0。

LoggingEnabled

Boolean

是否启用日志管理功能。

取值:

  • true:启用。

  • false(默认值):禁用。

DlqPolicy

Map

死信策略。

更多信息,请参考DlqPolicy属性

Tags

List

资源标签列表。

更多信息,请参考Tags属性

DlqPolicy语法

"DlqPolicy": {
  "MaxReceiveCount": Integer,
  "DeadLetterTargetQueue": String,
  "Enabled": Boolean
}

DlqPolicy属性

属性名称

类型

必须

允许更新

描述

约束

MaxReceiveCount

Integer

消息最大投递次数。

DeadLetterTargetQueue

String

死信消息投递目标队列。

Enabled

Boolean

是否开启死信消息投递。

Tags语法

"Tags": [{
  "Key": String,
  "Value": String
}]

Tags属性

属性名称

类型

必须

允许更新

描述

约束

Key

String

标签键。

Value

String

标签值。

返回值

Fn::GetAtt

  • QueueUrl:队列的URL。

  • ARN.WithSlash:队列的ARN。

  • QueueName:队列名称。

示例

ROSTemplateFormatVersion: '2015-09-01'
Parameters: {}
Resources:
  Queue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName: TestQueue
      MessageRetentionPeriod: 345600
Outputs:
  QueueName:
    Description: Queue name
    Value:
      Fn::GetAtt:
        - Queue
        - QueueName
  ARN:
    Description: The ARN for ALIYUN::ROS::CustomResource
    Value:
      Fn::GetAtt:
        - Queue
        - ARN
  ARN.WithSlash:
    Description: 'The ARN: acs:mns:$region:$accountid:/queues/$queueName'
    Value:
      Fn::GetAtt:
        - Queue
        - ARN.WithSlash
  QueueUrl:
    Description: URL of created queue
    Value:
      Fn::GetAtt:
        - Queue
        - QueueUrl
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
  },
  "Resources": {
    "Queue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": "TestQueue",
        "MessageRetentionPeriod": 345600
      }
    }
  },
  "Outputs": {
    "QueueName": {
      "Description": "Queue name",
      "Value": {
        "Fn::GetAtt": [
          "Queue",
          "QueueName"
        ]
      }
    },
    "ARN": {
      "Description": "The ARN for ALIYUN::ROS::CustomResource",
      "Value": {
        "Fn::GetAtt": [
          "Queue",
          "ARN"
        ]
      }
    },
    "ARN.WithSlash": {
      "Description": "The ARN: acs:mns:$region:$accountid:/queues/$queueName",
      "Value": {
        "Fn::GetAtt": [
          "Queue",
          "ARN.WithSlash"
        ]
      }
    },
    "QueueUrl": {
      "Description": "URL of created queue",
      "Value": {
        "Fn::GetAtt": [
          "Queue",
          "QueueUrl"
        ]
      }
    }
  }
}

更多示例,请参见创建主题、创建消息队列和描述订阅关系的组合YAML示例