Abonneren op gebeurtenissen voor een aangepaste onderwerp met Azure CLI

Met dit script maakt u een Event Grid-abonnement op de gebeurtenissen voor een aangepast onderwerp.

Als u dit voorbeeld wilt uitvoeren, installeert u de nieuwste versie van de Azure CLI. Voer eerst az login uit om een verbinding op te zetten met Azure.

Voorbeelden voor de Azure CLI zijn geschreven voor de bash-shell. Als u dit voorbeeld wilt uitvoeren in Windows PowerShell of opdrachtprompt, moet u mogelijk elementen van het script wijzigen.

Als u geen Azure-abonnement hebt, maakt u een gratis account voordat u begint.

Voor het voorbeeldscript van de preview is de Event Grid-extensie vereist. Voer az extension add --name eventgrid uit om deze te installeren.

Voorbeeldscript - stabiel

#!/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

Voorbeeldscript - preview-extensie

#!/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

Uitleg van het script

In dit script wordt de volgende opdracht gebruikt om het abonnement op de gebeurtenis te maken. Elke opdracht in de tabel is een koppeling naar opdracht-specifieke documentatie.

Opdracht Opmerkingen
az eventgrid event-subscription create Hiermee wordt een Event Grid-abonnement gemaakt.
az eventgrid event-subscription create - extensieversie Hiermee wordt een Event Grid-abonnement gemaakt.

Volgende stappen