すべてのプロダクト
Search
ドキュメントセンター

Resource Management:OOSを使用して、Apache RocketMQインスタンスのMessage Queue内のトピックとグループがインスタンスからタグを継承できるようにする

最終更新日:Dec 04, 2025

CloudOps Orchestration Service (OOS) コンソールでカスタムテンプレートを作成し、そのテンプレートを実行して、Apache RocketMQインスタンスのMessage Queueのトピックとグループがインスタンスからタグを継承できるようにすることができます。

制限事項

デフォルトでは、リージョンにデプロイされた OOS は、そのリージョンにおけるリソースのみ管理できます。 たとえば、中国 (杭州) リージョンにデプロイされた OOS を使用する場合、中国 (杭州) リージョンでのみ ECS インスタンスを管理できます。 ただし、OOS には、他のリージョンにデプロイされたリソースを管理する方法も存在します。 他のリージョンで API 操作を呼び出す場合は、ACS::ExecuteAPI 操作でリージョン ID を指定します。 この方法は使用しないことを推奨します。 したがって、この例では、OOSがデプロイされているリージョンが、管理するApache RocketMQインスタンスのMessage Queueが存在するリージョンと同じであることを確認する必要があります。 OOSの制限の詳細については、「制限」をご参照ください。

手順

  1. OOSコンソールにログインします。

  2. Ons_topicExtendInstanceTagsという名前の子テンプレートを作成します。

    サンプルテンプレートの詳細については、このトピックの「子テンプレート: インスタンスIDおよびその他の入力条件に基づくApache RocketMQインスタンスのMessage Queueのトピックのタグの更新」をご参照ください。 テンプレートの作成方法については、「テンプレートの作成」をご参照ください。

  3. Ons_groupExtendInstanceTagsという子テンプレートを作成します。

    サンプルテンプレートの詳細については、このトピックの「子テンプレート: インスタンスIDおよびその他の入力条件に基づくApache RocketMQインスタンスのMessage Queue内のグループのタグの更新」をご参照ください。 テンプレートの作成方法については、「テンプレートの作成」をご参照ください。

  4. 子テンプレートがネストされたRocketMQInstanceTagInheritという名前の親テンプレートを作成します。

    サンプルテンプレートの詳細については、このトピックの「親テンプレート: 入力条件に基づいて特定のリージョンに存在するApache RocketMQインスタンスのすべてのMessage Queueのトピックとグループのタグを更新する」をご参照ください。 テンプレートの作成方法については、「テンプレートの作成」をご参照ください。

  5. 親テンプレートRocketMQInstanceTagInheritの実行を作成します。

    次の設定を完了する必要があります。

    • 継承する必要があるタグが存在するリージョンを選択します。

    • 継承する必要があるタグを選択します。

    • タグを継承する必要があるリソースの種類を選択します。

    • 継承するタグと同じキーで値が異なる既存のタグの値を上書きするかどうかを指定します。

    実行の詳細については、「概要」をご参照ください。

  6. Message Queue for Apache RocketMQコンソールにログインし、指定したMessage Queue for Apache RocketMQインスタンスのトピックとグループがインスタンスのタグを継承しているかどうかを確認します。

子テンプレート: インスタンスIDおよびその他の入力条件に基づいて、Apache RocketMQインスタンスのMessage Queue内のトピックのタグを更新する

テンプレート名: Ons_topicExtendInstanceTags

テンプレートの内容:

FormatVersion: OOS-2019-06-01
Description: A template used for tag inheritance.
Parameters:
  regionId:
    Type: String
    Description:
      en: The id of region
      zh-cn: The region ID.
    Label:
      en: Region
      zh-cn: The region name.
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceId:
    Type: String
    Description:
      en: The id of OnsInstance
      zh-cn: The ID of the Message Queue for Apache RocketMQ instance.
    Label:
      en: InstanceId
      zh-cn: The ID of the Message Queue for Apache RocketMQ instance.
  tagKeys:
    Type: List
    Description: The tag keys.
  isUpdate:
    Type: Boolean
    Description: Specifies whether to overwrite the values of existing tags.
    Default: false
RamRole: ''
Tasks:
  - Name: getOnsInstanceAndTags
    Action: ACS::ExecuteAPI
    Description: ListTagResources
    Properties:
      Service: ONS
      API: ListTagResources
      Parameters:
        RegionId: '{{ regionId }}'
        ResourceId:
          - '{{instanceId}}'
        ResourceType: instance
    Outputs:
      onsTags:
        Type: Json
        ValueSelector: '.TagResources | map(select( .TagKey | test("^(?!acs).*"))) | map(select(.TagKey as $tagKey | {{tagKeys}} | index($tagKey) >=0)) '
  - Name: getTopicAndTags
    Action: ACS::ExecuteAPI
    Description: OnsTopicList
    Properties:
      Service: Ons
      API: OnsTopicList
      Parameters:
        RegionId: '{{ regionId }}'
        InstanceId: '{{instanceId}}'
    Outputs:
      updateTopicAndTags:
        Type: List
        ValueSelector: .Data.PublishInfoDo[] | {"Topic":.Topic, "Tags":.Tags}
  - Name: tagResources
    Action: ACS::ExecuteAPI
    Description: TagTopics
    Properties:
      Service: Ons
      API: TagResources
      Parameters:
        RegionId: '{{ regionId }}'
        ResourceId:
          Fn::Jq:
            - All
            - .Topic
            - '{{ACS::TaskLoopItem}}'
        Tag:
          Fn::If:
            - '{{isUpdate}}'
            - Fn::Jq:
                - All
                - '.[] |{"Key":.TagKey, "Value": .TagValue} '
                - '{{getOnsInstanceAndTags.onsTags}}'
            - Fn::Jq:
                - All
                - '.Tags.Tag as $topicTags | {{getOnsInstanceAndTags.onsTags}} | map(select(.TagKey as $tagKey | [$topicTags[].Key] | index($tagKey) <0)) |.[] |{"Key":.TagKey, "Value": .TagValue}'
                - '{{ACS::TaskLoopItem}}'
        ResourceType: topic
        InstanceId: '{{instanceId}}'
    Outputs:
      reqResult:
        Type: Json
        ValueSelector: .RequestId
    Loop:
      RateControl:
        Mode: Concurrency
        MaxErrors: 100
        Concurrency: 1
      Items: '{{getTopicAndTags.updateTopicAndTags}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult

子テンプレート: インスタンスIDおよびその他の入力条件に基づいて、Apache RocketMQインスタンスのMessage Queue内のグループのタグを更新する

テンプレート名: Ons_groupExtendInstanceTags

テンプレートの内容:

FormatVersion: OOS-2019-06-01
Description: A template used for tag inheritance.
Parameters:
  regionId:
    Type: String
    Description:
      en: The id of region
      zh-cn: The region ID.
    Label:
      en: Region
      zh-cn: The region name.
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceId:
    Type: String
    Description:
      en: The id of OnsInstance
      zh-cn: The ID of the Message Queue for Apache RocketMQ instance.
    Label:
      en: InstanceId
      zh-cn: The ID of the Message Queue for Apache RocketMQ instance.
  tagKeys:
    Type: List
    Description: The tag keys.
  isUpdate:
    Type: Boolean
    Description: Specifies whether to overwrite the values of existing tags.
    Default: false
RamRole: ''
Tasks:
  - Name: getOnsInstanceAndTags
    Action: ACS::ExecuteAPI
    Description: ListTagResources
    Properties:
      Service: ONS
      API: ListTagResources
      Parameters:
        RegionId: '{{ regionId }}'
        ResourceId:
          - '{{instanceId}}'
        ResourceType: instance
    Outputs:
      onsTags:
        Type: Json
        ValueSelector: '.TagResources | map(select( .TagKey | test("^(?!acs).*"))) | map(select(.TagKey as $tagKey | {{tagKeys}} | index($tagKey) >=0)) '
  - Name: getGroupAndTags
    Action: ACS::ExecuteAPI
    Description: OnsGroupList
    Properties:
      Service: Ons
      API: OnsGroupList
      Parameters:
        RegionId: '{{ regionId }}'
        InstanceId: '{{instanceId}}'
    Outputs:
      updateGroupAndTags:
        Type: List
        ValueSelector: .Data.SubscribeInfoDo[] | {"Group":.GroupId, "Tags":.Tags}
  - Name: tagResources
    Action: ACS::ExecuteAPI
    Description: TagGroups
    Properties:
      Service: Ons
      API: TagResources
      Parameters:
        RegionId: '{{ regionId }}'
        ResourceId:
          Fn::Jq:
            - All
            - .Group
            - '{{ACS::TaskLoopItem}}'
        Tag:
          Fn::If:
            - '{{isUpdate}}'
            - Fn::Jq:
                - All
                - '.[] |{"Key":.TagKey, "Value": .TagValue} '
                - '{{getOnsInstanceAndTags.onsTags}}'
            - Fn::Jq:
                - All
                - '.Tags.Tag as $groupTags | {{getOnsInstanceAndTags.onsTags}} | map(select(.TagKey as $tagKey | [$groupTags[].Key] | index($tagKey) <0)) |.[] |{"Key":.TagKey, "Value": .TagValue}'
                - '{{ACS::TaskLoopItem}}'
        ResourceType: group
        InstanceId: '{{instanceId}}'
    Outputs:
      reqResult:
        Type: Json
        ValueSelector: .RequestId
    Loop:
      RateControl:
        Mode: Concurrency
        MaxErrors: 100
        Concurrency: 1
      Items: '{{getGroupAndTags.updateGroupAndTags}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult

親テンプレート: 入力条件に基づいて特定のリージョンに存在するApache RocketMQインスタンスのすべてのMessage Queue内のトピックとグループのタグを更新する

テンプレート名: RocketMQInstanceTagInherit

テンプレートの内容:

FormatVersion: OOS-2019-06-01
Description: A template used for tag inheritance.
Parameters:
  regionIds:
    Type: List
    Description:
      en: The id of region
      zh-cn: The region ID.
    Label:
      en: Region
      zh-cn: The region name.
    AssociationProperty: RegionId
  tags:
    Type: List
    AssociationProperty: Tags
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::MQ::INSTANCE
    Description: The tags that you want topics and groups to inherit from the Message Queue for Apache RocketMQ instances to which the topics and groups belong. 
  resourceTypes:
    Type: List
    Description: The types of resources that need to inherit tags.
    AllowedValues:
      - topic
      - group
  isUpdate:
    Type: Boolean
    Description: Specifies whether to overwrite the values of existing tags that have the same keys as the tags to be inherited, but different values. 
    Default: false
RamRole: ''
Tasks:
  - Name: getOnsInstance
    Action: ACS::ExecuteAPI
    Description: OnsInstanceInServiceList
    Properties:
      Service: ONS
      API: OnsInstanceInServiceList
      Parameters:
        RegionId: '{{ACS::TaskLoopItem}}'
    Outputs:
      onsInstance:
        Type: List
        ValueSelector: '.Data.InstanceVO[] |. + {"RegionId": "{{ACS::TaskLoopItem}}" }'
    Loop:
      RateControl:
        Mode: Concurrency
        MaxErrors: 100
        Concurrency: 1
      Items: '{{regionIds}}'
      Outputs:
        allOnsInstances:
          AggregateType: Fn::ListJoin
          AggregateField: onsInstance
  - Name: isTagTopic
    Action: ACS::Choice
    Description:
      en: Choose next task by resource type
      zh-cn: Select the task that you want to run based on the resource type.
    Properties:
      DefaultTask: isTagGroup
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["topic"])
                  - '{{resourceTypes}}'
          NextTask: tagTopic
  - Name: tagTopic
    Action: ACS::Template
    Description:
      en: Update topic tags by ons instance tags
      zh-cn: Update tags of topics based on the tags of the Message Queue for Apache RocketMQ instances to which the topics belong.
    Properties:
      TemplateName: Ons_topicExtendInstanceTags
      Parameters:
        regionId:
          Fn::Jq:
            - First
            - .RegionId
            - '{{ACS::TaskLoopItem}}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys:
          Fn::Jq:
            - All
            - .[].Key
            - '{{tags}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl:
        Mode: Concurrency
        MaxErrors: 100
        Concurrency: 1
      Items:
        Fn::Jq:
          - All
          - .[][]
          - '{{getOnsInstance.allOnsInstances}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult
  - Name: isTagGroup
    Action: ACS::Choice
    Description:
      en: Choose next task by resource type
      zh-cn: Select the task that you want to run based on the resource type.
    Properties:
      DefaultTask: ACS::END
      Choices:
        - When:
            Fn::Equals:
              - true
              - Fn::Jq:
                  - First
                  - contains(["group"])
                  - '{{resourceTypes}}'
          NextTask: tagGroup
  - Name: tagGroup
    Action: ACS::Template
    Description:
      en: Update snapshot tags by ecs instance tags
      zh-cn: Update tags of groups based on the tags of the Message Queue for Apache RocketMQ instances to which the groups belong.
    Properties:
      TemplateName: Ons_groupExtendInstanceTags
      Parameters:
        regionId:
          Fn::Jq:
            - First
            - .RegionId
            - '{{ACS::TaskLoopItem}}'
        instanceId:
          Fn::Jq:
            - First
            - .InstanceId
            - '{{ACS::TaskLoopItem}}'
        tagKeys:
          Fn::Jq:
            - All
            - .[].Key
            - '{{tags}}'
        isUpdate: '{{isUpdate}}'
    Loop:
      RateControl:
        Mode: Concurrency
        MaxErrors: 100
        Concurrency: 1
      Items:
        Fn::Jq:
          - All
          - .[][]
          - '{{getOnsInstance.allOnsInstances}}'
      Outputs:
        tagResult:
          AggregateType: Fn::ListJoin
          AggregateField: reqResult