ALIYUN::MNS::Queue

Updated at:

The ALIYUN::MNS::Queue type is used to create a queue, which is a destination where messages are stored. Queues are classified as standard queues and delayed queues.

If the DelaySeconds property is not specified when you send a message, a message sent to a standard queue can be consumed immediately. A message sent to a delayed queue can be consumed only after the specified delay period.

Syntax

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

Properties

Property

Type

Required

Editable

Description

Constraints

QueueName

String

Yes

No

The name of the queue.

The queue name must be unique within the same account and region.

The name can be up to 256 characters in length, must start with a letter or digit, and can contain letters, digits, and hyphens (-).

DelaySeconds

Integer

No

Yes

By default, all messages sent to this queue are delayed by the number of seconds specified by the DelaySeconds property.

Valid values: 0 to 604800 (7 days).

Unit: seconds.

Default value: 0.

DlqPolicy

Map

No

Yes

The dead-letter policy.

For more information, see DlqPolicy properties.

LoggingEnabled

Boolean

No

Yes

Specifies whether to enable the log management feature.

Valid values:

  • true

  • false (default)

MaximumMessageSize

Integer

No

Yes

The maximum length of the message body that can be sent to this queue.

Valid values: 1024 (1 KB) to 65536 (64 KB).

Unit: bytes.

Default value: 65536 (64 KB).

MessageRetentionPeriod

Integer

No

Yes

The longest period for which a message remains in this queue. After the period specified by this property expires, the message is deleted, regardless of whether the message has been consumed.

Valid values: 60 (1 minute) to 604800 (7 days).

Unit: seconds.

Default value: 345600 (4 days).

PollingWaitSeconds

Integer

No

Yes

The maximum duration that a ReceiveMessage request for this queue waits when the queue contains no messages.

Valid values: 0 to 30.

Unit: seconds.

Default value: 0.

Tags

List

No

Yes

The list of resource tags.

For more information, see Tags properties.

VisibilityTimeout

Integer

No

Yes

The duration for which a message remains in the Inactive state after it is retrieved from this queue.

Valid values: 1 to 43200 (12 hours).

Unit: seconds.

Default value: 30.

DlqPolicy syntax

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

DlqPolicy properties

Property

Type

Required

Editable

Description

Constraints

DeadLetterTargetQueue

String

Yes

Yes

The target queue for dead-letter message delivery.

None.

Enabled

Boolean

Yes

Yes

Specifies whether to enable dead-letter message delivery.

None.

MaxReceiveCount

Integer

Yes

Yes

The maximum number of message deliveries.

None.

Tags syntax

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

Tags properties

Property

Type

Required

Editable

Description

Constraints

Key

String

Yes

No

The tag key.

None.

Value

String

No

No

The tag value.

None.

Return values

Fn::GetAtt

  • QueueUrl: the URL of the queue.

  • ARN.WithSlash: the Alibaba Cloud Resource Name (ARN) of the queue.

  • QueueName: the name of the queue.

Examples

Scenario 1: Create an MNS message queue

# Scenario 1: Create a simple MNS message queue with default configurations
# Create a simple MNS message queue with default configuration
ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create a simple MNS message queue with default configuration.
  en: Create a simple MNS message queue with default configuration.
Parameters:
  QueueName:
    Type: String
    Label:
      zh-cn: Queue Name
      en: Queue Name
    Description:
      zh-cn: The queue name. It must be unique within the same account and region and must start with a letter or digit.
      en: The queue name. Must be unique in the same account and region, and start with a letter or digit.
    Default: my-first-queue
    MinLength: 1
    MaxLength: 256
Resources:
  Queue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName:
        Ref: QueueName
Outputs:
  QueueName:
    Description:
      zh-cn: Queue name.
      en: Queue name.
    Label:
      zh-cn: Queue Name
      en: Queue Name
    Value:
      Fn::GetAtt:
        - Queue
        - QueueName
  QueueUrl:
    Description:
      zh-cn: The URL of the queue.
      en: The URL of the queue.
    Label:
      zh-cn: Queue URL
      en: Queue URL
    Value:
      Fn::GetAtt:
        - Queue
        - QueueUrl
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - QueueName
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create a simple MNS message queue with default configuration.",
    "en": "Create a simple MNS message queue with default configuration."
  },
  "Parameters": {
    "QueueName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Queue Name",
        "en": "Queue Name"
      },
      "Description": {
        "zh-cn": "The queue name. It must be unique within the same account and region and must start with a letter or digit.",
        "en": "The queue name. Must be unique in the same account and region, and start with a letter or digit."
      },
      "Default": "my-first-queue",
      "MinLength": 1,
      "MaxLength": 256
    }
  },
  "Resources": {
    "Queue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": {
          "Ref": "QueueName"
        }
      }
    }
  },
  "Outputs": {
    "QueueName": {
      "Description": {
        "zh-cn": "Queue name.",
        "en": "Queue name."
      },
      "Label": {
        "zh-cn": "Queue Name",
        "en": "Queue Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "Queue",
          "QueueName"
        ]
      }
    },
    "QueueUrl": {
      "Description": {
        "zh-cn": "The URL of the queue.",
        "en": "The URL of the queue."
      },
      "Label": {
        "zh-cn": "Queue URL",
        "en": "Queue URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "Queue",
          "QueueUrl"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "QueueName"
          ]
        }
      ]
    }
  }
}

Scenario 2: Business queue with message retention and a dead-letter queue

# Scenario 2: Create an MNS business queue and configure message retention, visibility timeout, and other parameters. Also create a dead-letter queue and associate a dead-letter policy.
# Create an MNS business queue with custom settings, plus a dead letter queue with DLQ policy for message failure fallback
ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create an MNS business queue and configure message retention, visibility timeout, long polling, and other parameters. Also create a dead-letter queue and associate a dead-letter policy to provide fallback handling for failed messages and log auditing.
  en: Create an MNS business queue with custom message retention, visibility timeout, long polling settings, plus a dead letter queue with DLQ policy for message failure fallback and log audit.
Parameters:
  QueueName:
    Type: String
    Label:
      zh-cn: Business Queue Name
      en: Business Queue Name
    Description:
      zh-cn: The name of the business message queue.
      en: The name of the business message queue.
    Default: order-processing-queue
  DlqQueueName:
    Type: String
    Label:
      zh-cn: Dead-Letter Queue Name
      en: DLQ Queue Name
    Description:
      zh-cn: The name of the dead-letter queue. It receives messages that fail delivery multiple times.
      en: The name of the dead letter queue that receives messages that fail delivery multiple times.
    Default: order-processing-dlq
  MaxReceiveCount:
    Type: Number
    Label:
      zh-cn: Maximum Delivery Count
      en: Max Receive Count
    Description:
      zh-cn: The maximum number of times that a message can be consumed. After the limit is exceeded, the message is delivered to the dead-letter queue.
      en: The maximum number of times a message can be received before being moved to the dead letter queue.
    Default: 3
    MinValue: 1
  MessageRetentionPeriod:
    Type: Number
    Label:
      zh-cn: Message Retention Period (Seconds)
      en: Message Retention Period (Seconds)
    Description:
      zh-cn: The longest period for which a message remains in the queue. Valid values: 60 to 604800 seconds.
      en: The maximum lifetime of a message in the queue, range 60 to 604800 seconds.
    Default: 345600
    MinValue: 60
    MaxValue: 604800
  VisibilityTimeout:
    Type: Number
    Label:
      zh-cn: Visibility Timeout (Seconds)
      en: Visibility Timeout (Seconds)
    Description:
      zh-cn: The duration for which a message is hidden after it is retrieved. Valid values: 1 to 43200 seconds.
      en: The invisibility duration after a message is received, range 1 to 43200 seconds.
    Default: 30
    MinValue: 1
    MaxValue: 43200
Resources:
  DlqQueue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName:
        Ref: DlqQueueName
      MessageRetentionPeriod: 604800
      LoggingEnabled: true
      Tags:
        - Key: QueueType
          Value: DeadLetter
        - Key: CreatedBy
          Value: ROS
  BusinessQueue:
    Type: ALIYUN::MNS::Queue
    DependsOn: DlqQueue
    Properties:
      QueueName:
        Ref: QueueName
      MessageRetentionPeriod:
        Ref: MessageRetentionPeriod
      VisibilityTimeout:
        Ref: VisibilityTimeout
      MaximumMessageSize: 65536
      DelaySeconds: 0
      PollingWaitSeconds: 10
      LoggingEnabled: true
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Ref: DlqQueueName
        MaxReceiveCount:
          Ref: MaxReceiveCount
      Tags:
        - Key: QueueType
          Value: Business
        - Key: Team
          Value: OrderService
        - Key: CreatedBy
          Value: ROS
Outputs:
  QueueName:
    Description:
      zh-cn: Business queue name.
      en: Business queue name.
    Label:
      zh-cn: Business Queue Name
      en: Business Queue Name
    Value:
      Fn::GetAtt:
        - BusinessQueue
        - QueueName
  QueueUrl:
    Description:
      zh-cn: The URL of the business queue.
      en: The URL of the business queue.
    Label:
      zh-cn: Business Queue URL
      en: Business Queue URL
    Value:
      Fn::GetAtt:
        - BusinessQueue
        - QueueUrl
  DlqQueueUrl:
    Description:
      zh-cn: The URL of the dead-letter queue.
      en: The URL of the dead letter queue.
    Label:
      zh-cn: Dead-Letter Queue URL
      en: DLQ Queue URL
    Value:
      Fn::GetAtt:
        - DlqQueue
        - QueueUrl
  QueueArn:
    Description:
      zh-cn: The ARN of the business queue, in slash format.
      en: The ARN of the business queue (with slash format).
    Label:
      zh-cn: Business Queue ARN
      en: Business Queue ARN
    Value:
      Fn::GetAtt:
        - BusinessQueue
        - ARN.WithSlash
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - QueueName
          - DlqQueueName
          - MaxReceiveCount
      - Parameters:
          - MessageRetentionPeriod
          - VisibilityTimeout
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create an MNS business queue and configure message retention, visibility timeout, long polling, and other parameters. Also create a dead-letter queue and associate a dead-letter policy to provide fallback handling for failed messages and log auditing.",
    "en": "Create an MNS business queue with custom message retention, visibility timeout, long polling settings, plus a dead letter queue with DLQ policy for message failure fallback and log audit."
  },
  "Parameters": {
    "QueueName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Business Queue Name",
        "en": "Business Queue Name"
      },
      "Description": {
        "zh-cn": "The name of the business message queue.",
        "en": "The name of the business message queue."
      },
      "Default": "order-processing-queue"
    },
    "DlqQueueName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Dead-Letter Queue Name",
        "en": "DLQ Queue Name"
      },
      "Description": {
        "zh-cn": "The name of the dead-letter queue. It receives messages that fail delivery multiple times.",
        "en": "The name of the dead letter queue that receives messages that fail delivery multiple times."
      },
      "Default": "order-processing-dlq"
    },
    "MaxReceiveCount": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Maximum Delivery Count",
        "en": "Max Receive Count"
      },
      "Description": {
        "zh-cn": "The maximum number of times that a message can be consumed. After the limit is exceeded, the message is delivered to the dead-letter queue.",
        "en": "The maximum number of times a message can be received before being moved to the dead letter queue."
      },
      "Default": 3,
      "MinValue": 1
    },
    "MessageRetentionPeriod": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Message Retention Period (Seconds)",
        "en": "Message Retention Period (Seconds)"
      },
      "Description": {
        "zh-cn": "The longest period for which a message remains in the queue. Valid values: 60 to 604800 seconds.",
        "en": "The maximum lifetime of a message in the queue, range 60 to 604800 seconds."
      },
      "Default": 345600,
      "MinValue": 60,
      "MaxValue": 604800
    },
    "VisibilityTimeout": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Visibility Timeout (Seconds)",
        "en": "Visibility Timeout (Seconds)"
      },
      "Description": {
        "zh-cn": "The duration for which a message is hidden after it is retrieved. Valid values: 1 to 43200 seconds.",
        "en": "The invisibility duration after a message is received, range 1 to 43200 seconds."
      },
      "Default": 30,
      "MinValue": 1,
      "MaxValue": 43200
    }
  },
  "Resources": {
    "DlqQueue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": {
          "Ref": "DlqQueueName"
        },
        "MessageRetentionPeriod": 604800,
        "LoggingEnabled": true,
        "Tags": [
          {
            "Key": "QueueType",
            "Value": "DeadLetter"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          }
        ]
      }
    },
    "BusinessQueue": {
      "Type": "ALIYUN::MNS::Queue",
      "DependsOn": "DlqQueue",
      "Properties": {
        "QueueName": {
          "Ref": "QueueName"
        },
        "MessageRetentionPeriod": {
          "Ref": "MessageRetentionPeriod"
        },
        "VisibilityTimeout": {
          "Ref": "VisibilityTimeout"
        },
        "MaximumMessageSize": 65536,
        "DelaySeconds": 0,
        "PollingWaitSeconds": 10,
        "LoggingEnabled": true,
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Ref": "DlqQueueName"
          },
          "MaxReceiveCount": {
            "Ref": "MaxReceiveCount"
          }
        },
        "Tags": [
          {
            "Key": "QueueType",
            "Value": "Business"
          },
          {
            "Key": "Team",
            "Value": "OrderService"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          }
        ]
      }
    }
  },
  "Outputs": {
    "QueueName": {
      "Description": {
        "zh-cn": "Business queue name.",
        "en": "Business queue name."
      },
      "Label": {
        "zh-cn": "Business Queue Name",
        "en": "Business Queue Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "BusinessQueue",
          "QueueName"
        ]
      }
    },
    "QueueUrl": {
      "Description": {
        "zh-cn": "The URL of the business queue.",
        "en": "The URL of the business queue."
      },
      "Label": {
        "zh-cn": "Business Queue URL",
        "en": "Business Queue URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "BusinessQueue",
          "QueueUrl"
        ]
      }
    },
    "DlqQueueUrl": {
      "Description": {
        "zh-cn": "The URL of the dead-letter queue.",
        "en": "The URL of the dead letter queue."
      },
      "Label": {
        "zh-cn": "Dead-Letter Queue URL",
        "en": "DLQ Queue URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "DlqQueue",
          "QueueUrl"
        ]
      }
    },
    "QueueArn": {
      "Description": {
        "zh-cn": "The ARN of the business queue, in slash format.",
        "en": "The ARN of the business queue (with slash format)."
      },
      "Label": {
        "zh-cn": "Business Queue ARN",
        "en": "Business Queue ARN"
      },
      "Value": {
        "Fn::GetAtt": [
          "BusinessQueue",
          "ARN.WithSlash"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "QueueName",
            "DlqQueueName",
            "MaxReceiveCount"
          ]
        },
        {
          "Parameters": [
            "MessageRetentionPeriod",
            "VisibilityTimeout"
          ]
        }
      ]
    }
  }
}

Scenario 3: Topic fan-out to subscriptions with a dead-letter queue

# Scenario 3: Create a complete message-driven architecture with an MNS topic, multiple subscription queues filtered by message tags, and a dead-letter queue to fan out order events to multiple systems and handle failed messages.
# Create a complete message-driven architecture (MNS topic + multiple subscription queues with tag filtering + DLQ) for order event fan-out distribution with failed message fallback
ROSTemplateFormatVersion: '2015-09-01'
Description:
  zh-cn: Create a complete message-driven architecture that includes an MNS topic, multiple subscription queues filtered by message tags, a dead-letter queue, and a dead-letter policy. This architecture fans out order events to multiple systems and provides fallback handling for failed messages.
  en: Create a complete message-driven architecture including an MNS topic, multiple subscription queues with message tag filtering, dead letter queues with DLQ policies, achieving order event fan-out distribution to multiple systems with failed message fallback.
Parameters:
  CommonName:
    Type: String
    Label:
      zh-cn: Resource Name Prefix
      en: Resource Name Prefix
    Description:
      zh-cn: The common prefix for all resource names.
      en: Unified name prefix for all resources.
    Default: order-events
  MaxReceiveCount:
    Type: Number
    Label:
      zh-cn: Maximum Delivery Count
      en: Max Receive Count
    Description:
      zh-cn: The maximum number of times that a message can be consumed. After the limit is exceeded, the message is delivered to the dead-letter queue.
      en: The maximum number of times a message can be received before being moved to the dead letter queue.
    Default: 3
    MinValue: 1
  MessageRetentionPeriod:
    Type: Number
    Label:
      zh-cn: Message Retention Period (Seconds)
      en: Message Retention Period (Seconds)
    Description:
      zh-cn: The longest period for which a message remains in the queue. Valid values: 60 to 604800 seconds.
      en: The maximum lifetime of a message in the queue, range 60 to 604800 seconds.
    Default: 345600
    MinValue: 60
    MaxValue: 604800
Resources:
  OrderTopic:
    Type: ALIYUN::MNS::Topic
    Properties:
      TopicName:
        Fn::Sub: ${CommonName}-topic
      MaximumMessageSize: 65536
      LoggingEnabled: true
      Tags:
        - Key: Domain
          Value: Order
        - Key: CreatedBy
          Value: ROS
  InventoryQueue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName:
        Fn::Sub: ${CommonName}-inventory-queue
      MessageRetentionPeriod:
        Ref: MessageRetentionPeriod
      VisibilityTimeout: 60
      PollingWaitSeconds: 10
      LoggingEnabled: true
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Fn::Sub: ${CommonName}-dlq
        MaxReceiveCount:
          Ref: MaxReceiveCount
      Tags:
        - Key: Subscriber
          Value: InventoryService
  NotificationQueue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName:
        Fn::Sub: ${CommonName}-notification-queue
      MessageRetentionPeriod:
        Ref: MessageRetentionPeriod
      VisibilityTimeout: 30
      PollingWaitSeconds: 10
      LoggingEnabled: true
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Fn::Sub: ${CommonName}-dlq
        MaxReceiveCount:
          Ref: MaxReceiveCount
      Tags:
        - Key: Subscriber
          Value: NotificationService
  AnalyticsQueue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName:
        Fn::Sub: ${CommonName}-analytics-queue
      MessageRetentionPeriod: 604800
      VisibilityTimeout: 300
      MaximumMessageSize: 65536
      PollingWaitSeconds: 15
      LoggingEnabled: true
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Fn::Sub: ${CommonName}-dlq
        MaxReceiveCount:
          Ref: MaxReceiveCount
      Tags:
        - Key: Subscriber
          Value: AnalyticsService
  DeadLetterQueue:
    Type: ALIYUN::MNS::Queue
    Properties:
      QueueName:
        Fn::Sub: ${CommonName}-dlq
      MessageRetentionPeriod: 604800
      LoggingEnabled: true
      Tags:
        - Key: QueueType
          Value: DeadLetter
        - Key: CreatedBy
          Value: ROS
  InventorySubscription:
    Type: ALIYUN::MNS::Subscription
    DependsOn:
      - OrderTopic
      - InventoryQueue
    Properties:
      TopicName:
        Fn::GetAtt:
          - OrderTopic
          - TopicName
      SubscriptionName:
        Fn::Sub: ${CommonName}-inventory-sub
      PushType: queue
      Endpoint:
        Fn::Sub:
          - acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:queues/${QueueName}
          - QueueName:
              Fn::GetAtt:
                - InventoryQueue
                - QueueName
      FilterTag: inventory
      NotifyContentFormat: JSON
      NotifyStrategy: EXPONENTIAL_DECAY_RETRY
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Fn::Sub: ${CommonName}-dlq
  NotificationSubscription:
    Type: ALIYUN::MNS::Subscription
    DependsOn:
      - OrderTopic
      - NotificationQueue
    Properties:
      TopicName:
        Fn::GetAtt:
          - OrderTopic
          - TopicName
      SubscriptionName:
        Fn::Sub: ${CommonName}-notification-sub
      PushType: queue
      Endpoint:
        Fn::Sub:
          - acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:queues/${QueueName}
          - QueueName:
              Fn::GetAtt:
                - NotificationQueue
                - QueueName
      FilterTag: notification
      NotifyContentFormat: JSON
      NotifyStrategy: BACKOFF_RETRY
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Fn::Sub: ${CommonName}-dlq
  AnalyticsSubscription:
    Type: ALIYUN::MNS::Subscription
    DependsOn:
      - OrderTopic
      - AnalyticsQueue
    Properties:
      TopicName:
        Fn::GetAtt:
          - OrderTopic
          - TopicName
      SubscriptionName:
        Fn::Sub: ${CommonName}-analytics-sub
      PushType: queue
      Endpoint:
        Fn::Sub:
          - acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:queues/${QueueName}
          - QueueName:
              Fn::GetAtt:
                - AnalyticsQueue
                - QueueName
      NotifyContentFormat: JSON
      NotifyStrategy: EXPONENTIAL_DECAY_RETRY
      DlqPolicy:
        Enabled: true
        DeadLetterTargetQueue:
          Fn::Sub: ${CommonName}-dlq
Outputs:
  TopicName:
    Description:
      zh-cn: MNS topic name.
      en: MNS topic name.
    Label:
      zh-cn: Topic Name
      en: Topic Name
    Value:
      Fn::GetAtt:
        - OrderTopic
        - TopicName
  TopicUrl:
    Description:
      zh-cn: The URL of the MNS topic.
      en: The URL of the MNS topic.
    Label:
      zh-cn: Topic URL
      en: Topic URL
    Value:
      Fn::GetAtt:
        - OrderTopic
        - TopicUrl
  InventoryQueueUrl:
    Description:
      zh-cn: The URL of the inventory service queue.
      en: Inventory service queue URL.
    Label:
      zh-cn: Inventory Queue URL
      en: Inventory Queue URL
    Value:
      Fn::GetAtt:
        - InventoryQueue
        - QueueUrl
  NotificationQueueUrl:
    Description:
      zh-cn: The URL of the notification service queue.
      en: Notification service queue URL.
    Label:
      zh-cn: Notification Queue URL
      en: Notification Queue URL
    Value:
      Fn::GetAtt:
        - NotificationQueue
        - QueueUrl
  AnalyticsQueueUrl:
    Description:
      zh-cn: The URL of the analytics service queue.
      en: Analytics service queue URL.
    Label:
      zh-cn: Analytics Queue URL
      en: Analytics Queue URL
    Value:
      Fn::GetAtt:
        - AnalyticsQueue
        - QueueUrl
  DeadLetterQueueUrl:
    Description:
      zh-cn: The URL of the dead-letter queue.
      en: Dead letter queue URL.
    Label:
      zh-cn: Dead-Letter Queue URL
      en: DLQ URL
    Value:
      Fn::GetAtt:
        - DeadLetterQueue
        - QueueUrl
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CommonName
          - MaxReceiveCount
          - MessageRetentionPeriod
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": {
    "zh-cn": "Create a complete message-driven architecture that includes an MNS topic, multiple subscription queues filtered by message tags, a dead-letter queue, and a dead-letter policy. This architecture fans out order events to multiple systems and provides fallback handling for failed messages.",
    "en": "Create a complete message-driven architecture including an MNS topic, multiple subscription queues with message tag filtering, dead letter queues with DLQ policies, achieving order event fan-out distribution to multiple systems with failed message fallback."
  },
  "Parameters": {
    "CommonName": {
      "Type": "String",
      "Label": {
        "zh-cn": "Resource Name Prefix",
        "en": "Resource Name Prefix"
      },
      "Description": {
        "zh-cn": "The common prefix for all resource names.",
        "en": "Unified name prefix for all resources."
      },
      "Default": "order-events"
    },
    "MaxReceiveCount": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Maximum Delivery Count",
        "en": "Max Receive Count"
      },
      "Description": {
        "zh-cn": "The maximum number of times that a message can be consumed. After the limit is exceeded, the message is delivered to the dead-letter queue.",
        "en": "The maximum number of times a message can be received before being moved to the dead letter queue."
      },
      "Default": 3,
      "MinValue": 1
    },
    "MessageRetentionPeriod": {
      "Type": "Number",
      "Label": {
        "zh-cn": "Message Retention Period (Seconds)",
        "en": "Message Retention Period (Seconds)"
      },
      "Description": {
        "zh-cn": "The longest period for which a message remains in the queue. Valid values: 60 to 604800 seconds.",
        "en": "The maximum lifetime of a message in the queue, range 60 to 604800 seconds."
      },
      "Default": 345600,
      "MinValue": 60,
      "MaxValue": 604800
    }
  },
  "Resources": {
    "OrderTopic": {
      "Type": "ALIYUN::MNS::Topic",
      "Properties": {
        "TopicName": {
          "Fn::Sub": "${CommonName}-topic"
        },
        "MaximumMessageSize": 65536,
        "LoggingEnabled": true,
        "Tags": [
          {
            "Key": "Domain",
            "Value": "Order"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          }
        ]
      }
    },
    "InventoryQueue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": {
          "Fn::Sub": "${CommonName}-inventory-queue"
        },
        "MessageRetentionPeriod": {
          "Ref": "MessageRetentionPeriod"
        },
        "VisibilityTimeout": 60,
        "PollingWaitSeconds": 10,
        "LoggingEnabled": true,
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Fn::Sub": "${CommonName}-dlq"
          },
          "MaxReceiveCount": {
            "Ref": "MaxReceiveCount"
          }
        },
        "Tags": [
          {
            "Key": "Subscriber",
            "Value": "InventoryService"
          }
        ]
      }
    },
    "NotificationQueue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": {
          "Fn::Sub": "${CommonName}-notification-queue"
        },
        "MessageRetentionPeriod": {
          "Ref": "MessageRetentionPeriod"
        },
        "VisibilityTimeout": 30,
        "PollingWaitSeconds": 10,
        "LoggingEnabled": true,
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Fn::Sub": "${CommonName}-dlq"
          },
          "MaxReceiveCount": {
            "Ref": "MaxReceiveCount"
          }
        },
        "Tags": [
          {
            "Key": "Subscriber",
            "Value": "NotificationService"
          }
        ]
      }
    },
    "AnalyticsQueue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": {
          "Fn::Sub": "${CommonName}-analytics-queue"
        },
        "MessageRetentionPeriod": 604800,
        "VisibilityTimeout": 300,
        "MaximumMessageSize": 65536,
        "PollingWaitSeconds": 15,
        "LoggingEnabled": true,
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Fn::Sub": "${CommonName}-dlq"
          },
          "MaxReceiveCount": {
            "Ref": "MaxReceiveCount"
          }
        },
        "Tags": [
          {
            "Key": "Subscriber",
            "Value": "AnalyticsService"
          }
        ]
      }
    },
    "DeadLetterQueue": {
      "Type": "ALIYUN::MNS::Queue",
      "Properties": {
        "QueueName": {
          "Fn::Sub": "${CommonName}-dlq"
        },
        "MessageRetentionPeriod": 604800,
        "LoggingEnabled": true,
        "Tags": [
          {
            "Key": "QueueType",
            "Value": "DeadLetter"
          },
          {
            "Key": "CreatedBy",
            "Value": "ROS"
          }
        ]
      }
    },
    "InventorySubscription": {
      "Type": "ALIYUN::MNS::Subscription",
      "DependsOn": [
        "OrderTopic",
        "InventoryQueue"
      ],
      "Properties": {
        "TopicName": {
          "Fn::GetAtt": [
            "OrderTopic",
            "TopicName"
          ]
        },
        "SubscriptionName": {
          "Fn::Sub": "${CommonName}-inventory-sub"
        },
        "PushType": "queue",
        "Endpoint": {
          "Fn::Sub": [
            "acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:queues/${QueueName}",
            {
              "QueueName": {
                "Fn::GetAtt": [
                  "InventoryQueue",
                  "QueueName"
                ]
              }
            }
          ]
        },
        "FilterTag": "inventory",
        "NotifyContentFormat": "JSON",
        "NotifyStrategy": "EXPONENTIAL_DECAY_RETRY",
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Fn::Sub": "${CommonName}-dlq"
          }
        }
      }
    },
    "NotificationSubscription": {
      "Type": "ALIYUN::MNS::Subscription",
      "DependsOn": [
        "OrderTopic",
        "NotificationQueue"
      ],
      "Properties": {
        "TopicName": {
          "Fn::GetAtt": [
            "OrderTopic",
            "TopicName"
          ]
        },
        "SubscriptionName": {
          "Fn::Sub": "${CommonName}-notification-sub"
        },
        "PushType": "queue",
        "Endpoint": {
          "Fn::Sub": [
            "acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:queues/${QueueName}",
            {
              "QueueName": {
                "Fn::GetAtt": [
                  "NotificationQueue",
                  "QueueName"
                ]
              }
            }
          ]
        },
        "FilterTag": "notification",
        "NotifyContentFormat": "JSON",
        "NotifyStrategy": "BACKOFF_RETRY",
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Fn::Sub": "${CommonName}-dlq"
          }
        }
      }
    },
    "AnalyticsSubscription": {
      "Type": "ALIYUN::MNS::Subscription",
      "DependsOn": [
        "OrderTopic",
        "AnalyticsQueue"
      ],
      "Properties": {
        "TopicName": {
          "Fn::GetAtt": [
            "OrderTopic",
            "TopicName"
          ]
        },
        "SubscriptionName": {
          "Fn::Sub": "${CommonName}-analytics-sub"
        },
        "PushType": "queue",
        "Endpoint": {
          "Fn::Sub": [
            "acs:mns:${ALIYUN::Region}:${ALIYUN::TenantId}:queues/${QueueName}",
            {
              "QueueName": {
                "Fn::GetAtt": [
                  "AnalyticsQueue",
                  "QueueName"
                ]
              }
            }
          ]
        },
        "NotifyContentFormat": "JSON",
        "NotifyStrategy": "EXPONENTIAL_DECAY_RETRY",
        "DlqPolicy": {
          "Enabled": true,
          "DeadLetterTargetQueue": {
            "Fn::Sub": "${CommonName}-dlq"
          }
        }
      }
    }
  },
  "Outputs": {
    "TopicName": {
      "Description": {
        "zh-cn": "MNS topic name.",
        "en": "MNS topic name."
      },
      "Label": {
        "zh-cn": "Topic Name",
        "en": "Topic Name"
      },
      "Value": {
        "Fn::GetAtt": [
          "OrderTopic",
          "TopicName"
        ]
      }
    },
    "TopicUrl": {
      "Description": {
        "zh-cn": "The URL of the MNS topic.",
        "en": "The URL of the MNS topic."
      },
      "Label": {
        "zh-cn": "Topic URL",
        "en": "Topic URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "OrderTopic",
          "TopicUrl"
        ]
      }
    },
    "InventoryQueueUrl": {
      "Description": {
        "zh-cn": "The URL of the inventory service queue.",
        "en": "Inventory service queue URL."
      },
      "Label": {
        "zh-cn": "Inventory Queue URL",
        "en": "Inventory Queue URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "InventoryQueue",
          "QueueUrl"
        ]
      }
    },
    "NotificationQueueUrl": {
      "Description": {
        "zh-cn": "The URL of the notification service queue.",
        "en": "Notification service queue URL."
      },
      "Label": {
        "zh-cn": "Notification Queue URL",
        "en": "Notification Queue URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "NotificationQueue",
          "QueueUrl"
        ]
      }
    },
    "AnalyticsQueueUrl": {
      "Description": {
        "zh-cn": "The URL of the analytics service queue.",
        "en": "Analytics service queue URL."
      },
      "Label": {
        "zh-cn": "Analytics Queue URL",
        "en": "Analytics Queue URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "AnalyticsQueue",
          "QueueUrl"
        ]
      }
    },
    "DeadLetterQueueUrl": {
      "Description": {
        "zh-cn": "The URL of the dead-letter queue.",
        "en": "Dead letter queue URL."
      },
      "Label": {
        "zh-cn": "Dead-Letter Queue URL",
        "en": "DLQ URL"
      },
      "Value": {
        "Fn::GetAtt": [
          "DeadLetterQueue",
          "QueueUrl"
        ]
      }
    }
  },
  "Metadata": {
    "ALIYUN::ROS::Interface": {
      "ParameterGroups": [
        {
          "Parameters": [
            "CommonName",
            "MaxReceiveCount",
            "MessageRetentionPeriod"
          ]
        }
      ]
    }
  }
}