首页 > 解决方案 > 如何使用 cli 创建系统主题

问题描述

我尝试创建一个系统主题。为此,我正在使用预览中的 eventgrid 扩展。

az eventgrid system-topic create \
    --name $topicName \
    --resource-group $resourceGroupName \
    --location $location \
    --topic-type microsoft.storage.storageaccounts \
    --source $storageId

但是,如果我尝试以这种方式获取 id/endpoint/key:

echo "Landing Topic Information:"
topicId=$(az eventgrid topic show \
  --name $topicName \
  --resource-group $resourceGroupName \
  --query id \
  --output tsv)
echo "Topic Id: $topicId"

topicEndpoint=$(az eventgrid topic show \
  --name $topicName \
  --resource-group $resourceGroupName \
  --query endpoint \
  --output tsv)
echo "Topic Endpoint: $topicEndpoint"

topicKey=$(az eventgrid topic key list \
  --name $topicName \
  --resource-group $resourceGroupName \
  --query key1 \
  --output tsv)
echo "Topic Key: $topicKey"

我收到一个错误:

Landing Topic Information:
The behavior of this command has been altered by the following extension: eventgrid
The Resource 'Microsoft.EventGrid/topics/xxx' under resource group 'xxxxxx-grp' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Topic Id: 
The behavior of this command has been altered by the following extension: eventgrid
The Resource 'Microsoft.EventGrid/topics/xxx' under resource group 'xxxxxx-grp' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Topic Endpoint: 
The behavior of this command has been altered by the following extension: eventgrid
The Resource 'Microsoft.EventGrid/topics/xxx' under resource group 'xxxxxx-grp' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix
Topic Key: 

我可以使用 Portal 查看系统主题

看结果,我更喜欢不使用扩展,所以问题是:如何使用没有扩展的 CLI 创建系统主题?*

命令行:

$ az --version
azure-cli                          2.7.0

command-modules-nspkg              2.0.3
core                               2.7.0
nspkg                              3.0.4
telemetry                          1.0.4

Extensions:
eventgrid                          0.4.9
interactive                        0.4.4

Python location '/opt/az/bin/python3'
Extensions directory '/home/angelcc/.azure/cliextensions'

Python (Linux) 3.6.10 (default, May 29 2020, 08:10:59) 
[GCC 9.3.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.

参考:

标签: azure-cliazure-eventgrid

解决方案


系统主题是 Azure 服务提供的内置主题。你在 Azure 订阅中看不到系统主题,因为发布者拥有这些主题,但你可以订阅它们。要订阅,您需要提供有关要从中接收事件的资源的信息。只要您有权访问该资源,就可以订阅其事件。

文档对此很清楚:Azure 服务存在系统主题。它们不是创建的,只是订阅的。您可以创建自定义主题。还可以创建合作伙伴主题。Event Domains代表您创建主题,无需创建主题,这些主题主要用于分区。

2020-06-10 更新:Microsoft 引入了一种明确定义系统主题的方法,而不是使用隐藏的自动生成主题。它不仅应该有助于提高可发现性,而且还可以更好地与整体 Azure 资源体验保持一致。

应该可以使用 Azure CLI 创建系统主题。它将需要使用az extension add -n eventgrid. 如果它是较早安装的,则需要使用az extension update -n eventgrid. 应更新文档以添加此细微差别。


推荐阅读