你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

查询事件网格订阅

本文介绍如何列出 Azure 订阅中的事件网格订阅。 查询现有事件网格订阅时,请务必了解不同类型的订阅。 根据要获取的订阅类型提供不同的参数。

注释

建议使用 Azure Az PowerShell 模块与 Azure 交互。 若要开始,请参阅安装 Azure PowerShell。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 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 westus2

对于 PowerShell,请使用:

Get-AzEventGridSubscription -Location westus2

若要获取对某个位置的自定义主题的订阅,请提供 Microsoft.EventGrid.Topics 的位置和主题类型。

对于 Azure CLI,请使用:

az eventgrid event-subscription list --topic-type-name "Microsoft.EventGrid.Topics" --location "westus2"

对于 PowerShell,请使用:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.EventGrid.Topics" -Location westus2

若要获取某个位置存储帐户的订阅,请提供 Microsoft.Storage.StorageAccounts 的位置和主题类型。

对于 Azure CLI,请使用:

az eventgrid event-subscription list --topic-type "Microsoft.Storage.StorageAccounts" --location westus2

对于 PowerShell,请使用:

Get-AzEventGridSubscription -TopicTypeName "Microsoft.Storage.StorageAccounts" -Location westus2

若要获取自定义主题的事件网格订阅,请提供自定义主题的名称及其资源组的名称。

对于 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

后续步骤