查询事件网格订阅

本文介绍了如何列出 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 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 resource show -n mystorage -g myResourceGroup --resource-type "Microsoft.Storage/storageaccounts" --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

后续步骤