Suscripción a eventos de un tema personalizado con la CLI de Azure

Este script crea una suscripción de Event Grid a los eventos de un tema personalizado.

Para ejecutar este ejemplo, instale la versión más reciente de la CLI de Azure. Para empezar, ejecute az login para crear una conexión con Azure.

Los ejemplos de la CLI de Azure están escritos para el shell bash. Para ejecutar este ejemplo en Windows PowerShell o en el símbolo del sistema, es posible que necesite cambiar algunos elementos del script.

Si no tiene una suscripción a Azure, cree una cuenta gratuita antes de empezar.

El script de ejemplo de la versión preliminar requiere la extensión de Event Grid. Para instalarla, ejecute az extension add --name eventgrid.

Script de ejemplo: estable

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

Script de ejemplo: extensión de la versión preliminar

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

Explicación del script

Este script usa el siguiente comando para crear la suscripción de eventos. Cada comando de la tabla crea un vínculo a documentación específica del comando.

Get-Help Notas
az eventgrid event-subscription create Cree una suscripción de Event Grid.
az eventgrid event-subscription create: versión de la extensión Cree una suscripción de Event Grid.

Pasos siguientes