全部產品
Search
文件中心

Resource Orchestration Service:ALIYUN::AMQP::Exchange

更新時間:Jun 15, 2024

ALIYUN::AMQP::Exchange類型用於建立Exchange。

文法

{
  "Type": "ALIYUN::AMQP::Exchange",
  "Properties": {
    "InstanceId": String,
    "AlternateExchange": String,
    "Internal": Boolean,
    "VirtualHost": String,
    "AutoDeleteState": Boolean,
    "ExchangeName": String,
    "ExchangeType": String
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

AutoDeleteState

Boolean

是否自動刪除。

取值:

  • true:自動刪除。當綁定到該Exchange的最後一個Queue解除綁定時,該Exchange會自動刪除。

  • false:不自動刪除。當綁定到該Exchange的最後一個Queue解除綁定時,該Exchange不會自動刪除。

ExchangeName

String

Exchange名稱。

Exchange名稱說明:

  • Exchange名稱只能包含字母、數字、短劃線(-)、底線(_)、半形句號(.)、井號(#)、正斜線(/)、at 符號(@),長度限制為1~255 字元。

  • 當Exchange被建立後,Exchange名稱不支援修改。如果您想修改Exchange名稱,只能刪除Exchange後重建。

ExchangeType

String

Exchange類型。

取值:

  • DIRECT:該類型路由規則會將訊息路由到Binding Key與Routing Key完全符合的Queue中。

  • TOPIC:該類型與DIRECT類型相似,使用Routing Key模式比對和字串比較的方式將訊息路由至綁定的Queue中。

  • FANOUT:該類型路由規則非常簡單,會把所有發送到該Exchange的訊息路由到所有與它綁定的Queue中,相當於廣播功能。

  • HEADERS:該類型與DIRECT類型相似。Headers Exchange使用Headers屬性代替Routing Key進行路由匹配。在綁定Headers Exchange和Queue時,設定綁定屬性的索引值對。在向Headers Exchange發送訊息時,設定訊息的Headers屬性索引值對,使用訊息Headers屬性索引值對和綁定屬性索引值對比較的方式將訊息路由至綁定的Queue中。

InstanceId

String

執行個體ID。

Internal

Boolean

是否為內部Exchange。

取值:

  • true:是內部Exchange。

  • false:不是內部Exchange。

VirtualHost

String

Exchange所在的Vhost名稱。

AlternateExchange

String

備份Exchange。

配置備份Exchange用於接收Exchange路由失敗的訊息。

傳回值

Fn::GetAtt

ExchangeName:Exchange名稱。

樣本

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  AutoDeleteState:
    AllowedValues:
    - 'True'
    - 'true'
    - 'False'
    - 'false'
    Description: 'Specifies whether the Auto Delete attribute is configured. Valid
      values:

      true: The Auto Delete attribute is configured. If the last queue that is bound
      to an exchange is unbound, the exchange is automatically deleted.

      false: The Auto Delete attribute is not configured. If the last queue that is
      bound to an exchange is unbound, the exchange is not automatically deleted.'
    Type: Boolean
  ExchangeName:
    Description: The name of the exchange.
    MaxLength: 255
    Type: String
  ExchangeType:
    AllowedValues:
    - FANOUT
    - DIRECT
    - TOPIC
    - HEADERS
    Description: 'The type of the exchange. Valid values:

      FANOUT: An exchange of this type routes all the received messages to all the
      queues bound to this exchange. You can use a fanout exchange to broadcast messages.

      DIRECT: An exchange of this type routes a message to the queue whose binding
      key is exactly the same as the routing key of the message.

      TOPIC: This type is similar to the direct exchange type. An exchange of this
      type routes a message to one or more queues based on the fuzzy match or multi-condition
      match result between the routing key of the message and the binding keys of
      the current exchange.

      HEADERS: Headers Exchange uses the Headers property instead of Routing Key for
      routing matching. When binding Headers Exchange and Queue, set the key-value
      pair of the binding property; when sending a message to the Headers Exchange,
      set the message''s Headers property key-value pair and use the message Headers
      The message is routed to the bound Queue by comparing the attribute key-value
      pair and the bound attribute key-value pair.'
    Type: String
  InstanceId:
    Description: InstanceId
    Type: String
  Internal:
    AllowedValues:
    - 'True'
    - 'true'
    - 'False'
    - 'false'
    Description: 'Specifies whether an exchange is an internal exchange. Valid values:

      false: The exchange is not an internal exchange.

      true: The exchange is an internal exchange.'
    Type: Boolean
  VirtualHost:
    Description: The name of the virtual host.
    Type: String
Resources:
  Exchange:
    Properties:
      AutoDeleteState:
        Ref: AutoDeleteState
      ExchangeName:
        Ref: ExchangeName
      ExchangeType:
        Ref: ExchangeType
      InstanceId:
        Ref: InstanceId
      Internal:
        Ref: Internal
      VirtualHost:
        Ref: VirtualHost
    Type: ALIYUN::AMQP::Exchange
Outputs:
  ExchangeName:
    Description: The name of the exchange.
    Value:
      Fn::GetAtt:
      - Exchange
      - ExchangeName

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "InstanceId": {
      "Type": "String",
      "Description": "InstanceId"
    },
    "Internal": {
      "Type": "Boolean",
      "Description": "Specifies whether an exchange is an internal exchange. Valid values:\nfalse: The exchange is not an internal exchange.\ntrue: The exchange is an internal exchange.",
      "AllowedValues": [
        "True",
        "true",
        "False",
        "false"
      ]
    },
    "VirtualHost": {
      "Type": "String",
      "Description": "The name of the virtual host."
    },
    "AutoDeleteState": {
      "Type": "Boolean",
      "Description": "Specifies whether the Auto Delete attribute is configured. Valid values:\ntrue: The Auto Delete attribute is configured. If the last queue that is bound to an exchange is unbound, the exchange is automatically deleted.\nfalse: The Auto Delete attribute is not configured. If the last queue that is bound to an exchange is unbound, the exchange is not automatically deleted.",
      "AllowedValues": [
        "True",
        "true",
        "False",
        "false"
      ]
    },
    "ExchangeName": {
      "Type": "String",
      "Description": "The name of the exchange.",
      "MaxLength": 255
    },
    "ExchangeType": {
      "Type": "String",
      "Description": "The type of the exchange. Valid values:\nFANOUT: An exchange of this type routes all the received messages to all the queues bound to this exchange. You can use a fanout exchange to broadcast messages.\nDIRECT: An exchange of this type routes a message to the queue whose binding key is exactly the same as the routing key of the message.\nTOPIC: This type is similar to the direct exchange type. An exchange of this type routes a message to one or more queues based on the fuzzy match or multi-condition match result between the routing key of the message and the binding keys of the current exchange.\nHEADERS: Headers Exchange uses the Headers property instead of Routing Key for routing matching. When binding Headers Exchange and Queue, set the key-value pair of the binding property; when sending a message to the Headers Exchange, set the message's Headers property key-value pair and use the message Headers The message is routed to the bound Queue by comparing the attribute key-value pair and the bound attribute key-value pair.",
      "AllowedValues": [
        "FANOUT",
        "DIRECT",
        "TOPIC",
        "HEADERS"
      ]
    }
  },
  "Resources": {
    "Exchange": {
      "Type": "ALIYUN::AMQP::Exchange",
      "Properties": {
        "InstanceId": {
          "Ref": "InstanceId"
        },
        "Internal": {
          "Ref": "Internal"
        },
        "VirtualHost": {
          "Ref": "VirtualHost"
        },
        "AutoDeleteState": {
          "Ref": "AutoDeleteState"
        },
        "ExchangeName": {
          "Ref": "ExchangeName"
        },
        "ExchangeType": {
          "Ref": "ExchangeType"
        }
      }
    }
  },
  "Outputs": {
    "ExchangeName": {
      "Description": "The name of the exchange.",
      "Value": {
        "Fn::GetAtt": [
          "Exchange",
          "ExchangeName"
        ]
      }
    }
  }
}