本文介绍如何列出Azure订阅中的事件网格订阅。 在查询现有事件网格订阅时,了解订阅的各种类型非常重要。 你需要根据要获取的订阅的类型提供不同的参数。
注意
建议使用 Azure Az PowerShell 模块与Azure交互。 若要开始,请参阅 Install Azure PowerShell。 若要了解如何迁移到 Az PowerShell 模块,请参阅 Migrate Azure PowerShell从 AzureRM 迁移到 Az。
资源组和Azure订阅
Azure订阅和资源组不是Azure资源。 因此,事件网格对资源组或Azure订阅的订阅与对Azure资源的订阅不具有相同的属性。 资源组或Azure订阅的事件网格订阅被视为全局订阅。
若要获取Azure订阅及其资源组的事件网格订阅,无需提供任何参数。 请确保已选择要查询的Azure订阅。 以下示例不会获取自定义主题或Azure资源的事件网格订阅。
对于Azure CLI,请使用:
az account set -s "My Azure Subscription"
az eventgrid event-subscription list
对于 PowerShell,请使用:
Set-AzContext -Subscription "My Azure Subscription"
Get-AzEventGridSubscription
若要获取Azure订阅的事件网格订阅,请提供主题类型 Microsoft。Resources.Subscriptions。
对于Azure CLI,请使用:
az eventgrid event-subscription list --topic-type-name "Microsoft.Resources.Subscriptions" --location global
对于 PowerShell,请使用:
Get-AzEventGridSubscription -TopicTypeName "Microsoft.Resources.Subscriptions"
若要获取Azure订阅中所有资源组的事件网格订阅,请提供主题类型 Microsoft。Resources.ResourceGroups。
对于Azure CLI,请使用:
az eventgrid event-subscription list --topic-type-name "Microsoft.Resources.ResourceGroups" --location global
对于 PowerShell,请使用:
Get-AzEventGridSubscription -TopicTypeName "Microsoft.Resources.ResourceGroups"
若要获取对特定资源组的事件网格订阅,请将资源组的名称作为参数提供。
对于Azure CLI,请使用:
az eventgrid event-subscription list --resource-group myResourceGroup --location global
对于 PowerShell,请使用:
Get-AzEventGridSubscription -ResourceGroupName myResourceGroup
自定义主题和Azure资源
事件网格自定义主题是Azure资源。 因此,可以采用相同的方式查询对自定义主题和其他资源(例如 Blob 存储帐户)的事件网格订阅。 若要获取对自定义主题的事件网格订阅,必须提供用来标识资源或标识资源位置的参数。 在您的 Azure 订阅中,无法广泛查询资源的事件网格订阅。
若要获取对某个位置中的自定义主题和其他资源的事件网格订阅,请提供该位置的名称。
对于Azure CLI,请使用:
az eventgrid event-subscription list --location chinaeast
对于 PowerShell,请使用:
Get-AzEventGridSubscription -Location chinaeast
若要获取某个位置的自定义主题订阅,请提供该位置和主题类型 Microsoft.EventGrid.Topics。
对于Azure CLI,请使用:
az eventgrid event-subscription list --topic-type-name "Microsoft.EventGrid.Topics" --location "chinaeast"
对于 PowerShell,请使用:
Get-AzEventGridSubscription -TopicTypeName "Microsoft.EventGrid.Topics" -Location chinaeast
若要获取特定位置的存储帐户订阅,请提供位置和Microsoft.Storage.StorageAccounts的主题类型。
对于Azure CLI,请使用:
az eventgrid event-subscription list --topic-type "Microsoft.Storage.StorageAccounts" --location chinaeast
对于 PowerShell,请使用:
Get-AzEventGridSubscription -TopicTypeName "Microsoft.Storage.StorageAccounts" -Location chinaeast
若要获取对某个自定义主题的事件网格订阅,请提供该自定义主题的名称及其资源组的名称。
对于Azure CLI,请使用:
az eventgrid event-subscription list --topic-name myCustomTopic --resource-group myResourceGroup
对于 PowerShell,请使用:
Get-AzEventGridSubscription -TopicName myCustomTopic -ResourceGroupName myResourceGroup
若要获取对特定资源的事件网格订阅,请提供资源 ID。
对于Azure CLI,请使用:
resourceid=$(az storage account show -g myResourceGroup -n myStorageAccount --query id --output tsv)
az eventgrid event-subscription list --resource-id $resourceid
对于 PowerShell,请使用:
$resourceid = (Get-AzResource -Name mystorage -ResourceGroupName myResourceGroup).ResourceId
Get-AzEventGridSubscription -ResourceId $resourceid
后续步骤
- 有关事件传送和重试的信息,请参阅事件网格消息传送和重试。
- 有关事件网格的介绍,请参阅关于事件网格。
- 若要快速开始使用 Event Grid,请参阅 创建自定义事件并使用 Azure 事件网格 路由自定义事件。