如何使用CLI创建系统主题

时间:2020-06-09 19:48:15

标签: azure-cli azure-eventgrid

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

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

但是,如果我尝试通过这种方式获取ID /端点/密钥:

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: 

我可以使用门户网站查看系统主题

看结果,我宁愿不使用扩展,所以问题是:如何使用不带扩展名的CLI创建系统主题?*

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.

参考:

2 个答案:

答案 0 :(得分:2)

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

documentation在这一点上很明确:Azure服务存在系统主题。它们不是创建的,仅是订阅的。您可以创建一个custom topics。也可以创建partner topicsEvent Domains代表您创建主题,无需创建主题,这些主题主要用于分区。

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

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

答案 1 :(得分:0)

目前看来,仅可以通过eventgrid扩展名手动创建系统主题。

关于这一点的I created an issue to fix it尚不清楚:{{3}}

由于错误列表而导致的原因:

  • 我使用了错误的命令来获取信息:az eventgrid topic show应该是az eventgrid system-topic show
  • 系统主题没有端点,因为只有系统资源才能在其中发布消息。
  • 系统主题没有,因为只有系统资源才能在其中发布消息。