全部產品
Search
文件中心

:ALIYUN::KAFKA::Topic

更新時間:Apr 18, 2025

ALIYUN::KAFKA::Topic類型用於建立Topic。

文法

{
  "Type": "ALIYUN::KAFKA::Topic",
  "Properties": {
    "InstanceId": String,
    "Topic": String,
    "Remark": String,
    "PartitionNum": Integer,
    "ReplicationFactor": Integer,
    "LocalTopic": Boolean,
    "CompactTopic": Boolean,
    "Config": Map,
    "MinInsyncReplicas": Integer,
    "Tags": List
  }
}

屬性

屬性名稱

類型

必須

允許更新

描述

約束

InstanceId

String

執行個體ID。

Topic

String

Topic的名稱。

長度為3~64個字元,可包含英文字母、數字、底線(_)和短劃線(-)。

說明

Topic名稱一旦建立,將無法修改。

Remark

String

Topic的備忘資訊。

長度為3~64個字元,可包含英文字母、數字、底線(_)和短劃線(-)。

PartitionNum

Integer

Topic的分區數。

取值範圍:1~48。

建議分區數取值為6的倍數,減少資料扭曲風險。

ReplicationFactor

Integer

Topic的副本數。

當LocalTopic取值為true時,該參數有效。

取值範圍:1~3。

說明

副本數為1時,有資料丟失的風險,請謹慎設定。

LocalTopic

Boolean

Topic的儲存引擎。

取值:

  • false:雲端儲存。

  • true:Local儲存。

CompactTopic

Boolean

日誌清理策略。

當LocalTopic取值為true時,該參數有效。

取值:

  • false:訊息清理策略。在磁碟容量充足的情況下,保留在最長保留時間範圍內的訊息;在磁碟容量不足時(一般磁碟使用率超過85%視為不足),將提前刪除舊訊息,以保證服務可用性。

  • true:Log Compaction日誌清理策略。相同Key的訊息,最新的Value值一定會被保留。

Config

Map

補充配置。

當LocalTopic取值為true時,該參數有效。

取值樣本:{"replications": 3},其中replications表示Topic副本數,取值範圍為1~3。

MinInsyncReplicas

Integer

最小ISR同步複本數。

當LocalTopic取值為true時,該參數有效。

取值範圍:1~3,取值需小於Topic副本數。

Tags

List

標籤。

更多資訊,請參見Tags屬性

Tags文法

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

Tags屬性

屬性名稱

類型

必須

允許更新

描述

約束

Key

String

標籤鍵。

長度為1~128個字元,不能以aliyunacs:開頭,不能包含http://或者https://

Value

String

標籤值。

長度為1~128個字元,不能以aliyunacs:開頭,不能包含http://或者https://

傳回值

Fn::GetAtt

  • InstanceId:執行個體ID。

  • Topic:Topic的名稱。

  • Arn:阿里雲資源名稱。

樣本

ROSTemplateFormatVersion: '2015-09-01'
Description: Test create Kafka Topic
Parameters:
  InstanceId:
    Type: String
    Description: Kafka Instance Id
    Default: alikafka_****
  Topic:
    Type: String
    Description: |-
      The name of the topic. The value of this parameter must meet the following requirements:
      The name can only contain letters, digits, hyphens (-), and underscores (_).
      The name must be 3 to 64 characters in length, and will be automatically truncated
      if it contains more characters.
      The name cannot be modified after being created.
    Default: myTopic
  Remark:
    Type: String
    Description: |-
      The description of the topic. The value of this parameter must meet the following
      requirements:
      The value can only contain letters, digits, hyphens (-), and underscores (_).
      The value must be 3 to 64 characters in length.
    Default: test
Resources:
  Topic:
    Type: ALIYUN::KAFKA::Topic
    Properties:
      InstanceId:
        Ref: InstanceId
      Topic:
        Ref: TopicName
      Remark:
        Ref: Remark
Outputs:
  TopicName:
    Value:
      Fn::GetAtt:
        - Topic
        - Topic
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "Test create Kafka Topic",
  "Parameters": {
    "InstanceId": {
      "Type": "String",
      "Description": "Kafka Instance Id",
      "Default": "alikafka_****"
    },
    "Topic": {
      "Type": "String",
      "Description": "The name of the topic. The value of this parameter must meet the following requirements:\nThe name can only contain letters, digits, hyphens (-), and underscores (_).\nThe name must be 3 to 64 characters in length, and will be automatically truncated\nif it contains more characters.\nThe name cannot be modified after being created.",
      "Default": "myTopic"
    },
    "Remark": {
      "Type": "String",
      "Description": "The description of the topic. The value of this parameter must meet the following\nrequirements:\nThe value can only contain letters, digits, hyphens (-), and underscores (_).\nThe value must be 3 to 64 characters in length.",
      "Default": "test"
    }
  },
  "Resources": {
    "Topic": {
      "Type": "ALIYUN::KAFKA::Topic",
      "Properties": {
        "InstanceId": {
          "Ref": "InstanceId"
        },
        "Topic": {
          "Ref": "TopicName"
        },
        "Remark": {
          "Ref": "Remark"
        }
      }
    }
  },
  "Outputs": {
    "TopicName": {
      "Value": {
        "Fn::GetAtt": [
          "Topic",
          "Topic"
        ]
      }
    }
  }
}