Todos os produtos
Search
Central de documentação

Resource Orchestration Service:ALIYUN::MNS::Queue

Última atualização: Oct 10, 2026

O tipo ALIYUN::MNS::Queue é usado para criar uma fila, que é o destino onde as mensagens são armazenadas. As filas são classificadas em filas padrão e filas com atraso.

Se a propriedade DelaySeconds não for especificada ao enviar uma mensagem, uma mensagem enviada para uma fila padrão poderá ser consumida imediatamente. Uma mensagem enviada para uma fila com atraso só poderá ser consumida após o período de atraso especificado.

Sintaxe

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

Propriedades

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

QueueName

String

Sim

Não

O nome da fila.

O nome da fila deve ser único na mesma conta e região.

O nome pode ter até 256 caracteres, deve começar com uma letra ou dígito e pode conter letras, dígitos e hifens (-).

DelaySeconds

Integer

Não

Sim

Por padrão, todas as mensagens enviadas para esta fila são atrasadas pelo número de segundos especificado pela propriedade DelaySeconds.

Valores válidos: 0 a 604800 (7 dias).

Unidade: segundos.

Valor padrão: 0.

DlqPolicy

Map

Não

Sim

A política de dead letter.

Para mais informações, consulte Propriedades de DlqPolicy.

LoggingEnabled

Boolean

Não

Sim

Especifica se o recurso de gerenciamento de logs deve ser ativado.

Valores válidos:

  • true

  • false (padrão)

MaximumMessageSize

Integer

Não

Sim

O tamanho máximo do corpo da mensagem que pode ser enviado para esta fila.

Valores válidos: 1024 (1 KB) a 65536 (64 KB).

Unidade: bytes.

Valor padrão: 65536 (64 KB).

MessageRetentionPeriod

Integer

Não

Sim

O período máximo durante o qual uma mensagem permanece nesta fila. Após o término do período especificado por esta propriedade, a mensagem é excluída, independentemente de ter sido consumida ou não.

Valores válidos: 60 (1 minuto) a 604800 (7 dias).

Unidade: segundos.

Valor padrão: 345600 (4 dias).

PollingWaitSeconds

Integer

Não

Sim

A duração máxima que uma solicitação ReceiveMessage para esta fila aguarda quando a fila não contém mensagens.

Valores válidos: 0 a 30.

Unidade: segundos.

Valor padrão: 0.

Tags

List

Não

Sim

A lista de tags de recurso.

Para mais informações, consulte Propriedades de Tags.

VisibilityTimeout

Integer

Não

Sim

A duração durante a qual uma mensagem permanece no estado inativo após ser recuperada desta fila.

Valores válidos: 1 a 43200 (12 horas).

Unidade: segundos.

Valor padrão: 30.

Sintaxe de DlqPolicy

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

Propriedades de DlqPolicy

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

DeadLetterTargetQueue

String

Sim

Sim

A fila de destino para entrega de mensagens dead letter.

Nenhuma.

Enabled

Boolean

Sim

Sim

Especifica se a entrega de mensagens dead letter deve ser ativada.

Nenhuma.

MaxReceiveCount

Integer

Sim

Sim

O número máximo de entregas de mensagens.

Nenhuma.

Sintaxe de Tags

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

Propriedades de Tags

Propriedade

Tipo

Obrigatório

Editável

Descrição

Restrições

Key

String

Sim

Não

A chave da tag.

Nenhuma.

Value

String

Não

Não

O valor da tag.

Nenhuma.

Valores de retorno

Fn::GetAtt

  • QueueUrl: a URL da fila.

  • ARN.WithSlash: o ARN (Alibaba Cloud Resource Name) da fila.

  • QueueName: o nome da fila.

Exemplos

Cenário 1: Criar uma fila de mensagens MNS

# 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"
          ]
        }
      ]
    }
  }
}

Cenário 2: Fila de negócios com retenção de mensagens e fila dead letter

# 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"
          ]
        }
      ]
    }
  }
}

Cenário 3: Fan-out de tópico para assinaturas com fila dead letter

# 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"
          ]
        }
      ]
    }
  }
}