使用 Azure CLI 创建事件网格自定义主题Create Event Grid custom topic with Azure CLI

此脚本创建事件网格自定义主题。This script creates an Event Grid custom topic.

若要运行此示例,请安装最新版本的 Azure CLITo run this sample, install the latest version of the Azure CLI. 若要开始,请运行 az login 以创建与 Azure 的连接。To start, run az login to create a connection with Azure.

适用于 Azure CLI 的示例是针对 bash shell 编写的。Samples for the Azure CLI are written for the bash shell. 若要在 Windows PowerShell 或命令提示符中运行此示例,可能需要更改脚本的元素。To run this sample in Windows PowerShell or Command Prompt, you may need to change elements of the script.

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

示例脚本Sample script

#!/bin/bash

# Give your custom topic a unique name
myTopic=demoContosoTopic

# Provice name for resource group
myResourceGroup=demoResourceGroup

# Select the Azure subscription to contain the custom topic.
az account set --subscription "<name or ID of the subscription>"

# Create resource group
az group create --name $myResourceGroup --location chinanorth2

# Create custom topic
az eventgrid topic create --resource-group $myResourceGroup --name $myTopic --location chinanorth2

# Retrieve endpoint and key to use when publishing to the topic
endpoint=$(az eventgrid topic show --name $myTopic -g $myResourceGroup --query "endpoint" --output tsv)
key=$(az eventgrid topic key list --name $myTopic -g $myResourceGroup --query "key1" --output tsv)

echo $endpoint
echo $key

脚本说明Script explanation

此脚本使用以下命令创建自定义主题。This script uses the following command to create the custom topic. 表中的每条命令链接到特定于命令的文档。Each command in the table links to command-specific documentation.

CommandCommand 说明Notes
az eventgrid topic createaz eventgrid topic create 创建事件网格自定义主题。Create an Event Grid custom topic.

后续步骤Next steps