Azure CLI ile bir özel konu için olaylara abone olma
Bu betik, bir özel konu için olaylara bir Event Grid aboneliği oluşturur.
Bu örneği çalıştırmak için, Azure CLI'nin en son sürümünü yükler. Başlangıç olarak, Azure ile bağlantı oluşturmak için az login komutunu çalıştırın.
Azure CLı için örnekler, Shell için yazılmıştır bash . Bu örneği Windows PowerShell veya komut Isteminde çalıştırmak için betiğin öğelerini değiştirmeniz gerekebilir.
Azure aboneliğiniz yoksa başlamadan önce ücretsiz bir hesap oluşturun.
Önizleme örnek betiği için Event Grid uzantısı gerekir. Yüklemek için az extension add --name eventgrid komutunu çalıştırın.
Örnek betik - kararlı
#!/bin/bash
# Provide the name of the topic you are subscribing to
myTopic=demoContosoTopic
# Provide the name of the resource group containing the custom topic
resourceGroup=demoResourceGroup
# Provide an endpoint for handling the events.
myEndpoint="<endpoint URL>"
# Select the Azure subscription that contains the custom topic.
az account set --subscription "<name or ID of the subscription>"
# Subscribe to the custom event. Include the resource group that contains the custom topic.
az eventgrid event-subscription create \
--resource-group $resourceGroup \
--topic-name $myTopic \
--name demoSubscription \
--endpoint $myEndpoint
Örnek betik - önizleme uzantısı
#!/bin/bash
# You must have the latest version of the Event Grid preview extension.
# If you have not installed previously:
# az extension add -n eventgrid
# If you have installed previously:
# az extension update -n eventgrid
# Provide the name of the topic you are subscribing to
myTopic=demoContosoTopic
# Provide the name of the resource group containing the custom topic
resourceGroup=demoResourceGroup
# Provide an endpoint for handling the events.
myEndpoint="<endpoint URL>"
# Select the Azure subscription that contains the custom topic.
az account set --subscription "<name or ID of the subscription>"
# Get the resource ID of the custom topic
topicID=$(az eventgrid topic show --name $myTopic -g $resourceGroup --query id --output tsv)
# Subscribe to the custom event. Include the resource group that contains the custom topic.
az eventgrid event-subscription create \
--source-resource-id $topicID \
--name demoSubscription \
--endpoint $myEndpoint
Betik açıklaması
Bu betik, olay aboneliğini oluşturmak için aşağıdaki komutu kullanır. Tablodaki her komut, komuta özgü belgelere yönlendirir.
| Komut | Notlar |
|---|---|
| az eventgrid event-subscription create | Event Grid aboneliği oluşturun. |
| az eventgrid event-subscription create - uzantı sürümü | Event Grid aboneliği oluşturun. |
Sonraki adımlar
- Abonelikleri sorgulama hakkında bilgi edinmek için bkz. Event Grid aboneliklerini sorgulama.
- Azure CLI hakkında daha fazla bilgi için bkz. Azure CLI belgeleri.