Compartilhar via

使用Azure CLI创建、查看和管理事件网格系统主题

本文介绍如何使用Azure CLI创建和管理系统主题。 有关系统主题的概述,请参阅 系统主题

安装Azure CLI扩展

对于 Azure CLI,需要 Event Grid 扩展

对于本地安装:

  1. 安装 Azure CLI。 通过检查 az --version,确保你拥有最新版本。
  2. 卸载早期版本的扩展: az extension remove -n eventgrid
  3. 使用 az extension add -n eventgrid 安装 eventgrid 扩展

创建系统主题

  • 若要首先在Azure源上创建系统主题,然后为该主题创建事件订阅,请参阅以下参考主题:

    • az eventgrid system-topic create(创建事件网格系统主题)

      # Get the ID of the Azure source (for example: Azure Storage account)
      storageid=$(az storage account show \
              --name <AZURE STORAGE ACCOUNT NAME> \
              --resource-group <AZURE RESOURCE GROUP NAME> \
                  --query id --output tsv)
      
      # Create the system topic on the Azure source (example: Azure Storage account)
      az eventgrid system-topic create \
          -g <AZURE RESOURCE GROUP NAME> \
          --name <SPECIFY SYSTEM TOPIC NAME> \
          --location <LOCATION> \
          --topic-type microsoft.storage.storageaccounts \
          --source $storageid
      

      有关可用于创建系统主题的topic-type值的列表,请运行以下命令。 这些主题类型值表示支持创建系统主题的事件源。 请忽略列表中的 Microsoft.EventGrid.TopicsMicrosoft.EventGrid.Domains

      az eventgrid topic-type  list --output json | grep -w id
      
    • Az EventGrid 系统主题事件订阅创建

      az eventgrid system-topic event-subscription create --name <SPECIFY EVENT SUBSCRIPTION NAME> \
          -g rg1 --system-topic-name <SYSTEM TOPIC NAME> \
          --endpoint <ENDPOINT URL>		  
      
  • 若要在为Azure源创建事件订阅时创建系统主题(隐式),请使用 az eventgrid event-subscription create 方法。 下面是一个示例:

    storageid=$(az storage account show --name <AZURE STORAGE ACCOUNT NAME> --resource-group <AZURE RESOURCE GROUP NAME> --query id --output tsv)
    endpoint=<ENDPOINT URL>
    
    az eventgrid event-subscription create \
      --source-resource-id $storageid \
      --name <EVENT SUBSCRIPTION NAME> \
      --endpoint $endpoint
    

    有关分步说明的教程,请参阅 “订阅存储帐户”。

查看所有系统主题

若要查看所选系统主题的所有系统主题和详细信息,请使用以下命令:

删除系统主题

若要删除系统主题,请使用以下命令:

后续步骤

请参阅 Azure 事件网格 部分中的 System 主题,详细了解Azure 事件网格支持的系统主题和主题类型。