Share via


使用 Azure CLI 來建立、檢視和管理事件方格系統主題

本文顯示如何使用 Azure CLI 來建立和管理系統主題。 如需系統主題的概觀,請參閱系統主題

安裝 Azure CLI 擴充功能

對於 Azure CLI,您需要事件方格擴充功能

在 Cloud Shell 中:

  • 如果您先前已安裝過該延伸模組,則請予以更新:az extension update -n eventgrid
  • 如果您先前尚未安裝過該延伸模組,則請予以安裝:az extension add -n eventgrid

針對本機安裝:

  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 system-topic event-subscription create

      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 事件方格所支援的系統主題和主題類型,請參閱 Azure 事件方格中的系統主題一節。