Question

Difficulty: MediumImplement Azure Event Grid Solutions

You are developing a solution that uses Azure Event Grid to handle custom application events. You need to create a new custom topic, configure a subscription to route events to an Azure Function, and then publish a test event to verify the endpoint routing using an API client.

Which five actions should you perform in sequence? To answer, arrange the actions in the correct order.

  1. 1Create the custom Event Grid topic.
  2. 2Retrieve the endpoint URL and access key for the custom topic.
  3. 3Create the event subscription that routes events to the Azure Function.
  4. 4Construct a JSON array containing a valid Event Grid event object.
  5. 5Send an HTTP POST request containing the JSON array to the custom topic endpoint with the access key in the headers.

Answer

Create the custom Event Grid topic, retrieve the endpoint URL and access key, create the event subscription, construct the JSON array with the event object, and send the HTTP POST request to the custom topic endpoint with the access key in the headers.
To configure and verify Event Grid routing, you must follow a logical sequence: first, create the target resource (the custom topic). Once created, retrieve the endpoint URI and SAS key for authorization. Then, create the event subscription so that when you publish the test event, it will actually be routed to the Azure Function rather than being dropped. Next, format the event payload as a JSON array to comply with the Event Grid schema. Finally, send an HTTP POST request to the endpoint, specifying the SAS key in the headers and the JSON array in the request body.

Step-by-Step Solution

1
Create the custom Event Grid topic resource in Azure.
The topic resource is created and allocated a unique endpoint.
You cannot obtain connection credentials or bind subscriptions without first creating the topic.
2
Retrieve the access key and the endpoint URI from the created topic.
The topic endpoint URL and primary access key are obtained.
These values are required to authenticate and direct the HTTP request when publishing events.
3
Create an event subscription on the custom topic targeting the Azure Function endpoint.
The handler endpoint is registered to listen to events from the custom topic.
If events are published before a subscription exists, the custom topic will discard them immediately.
4
Prepare the message payload as a JSON array containing a schema-compliant Event Grid event.
A valid Event Grid JSON payload is created.
Event Grid endpoints reject payloads that do not match the required JSON array structure and schema properties (e.g., id, subject, eventType, eventTime, data).
5
Send an HTTP POST request to the endpoint with the JSON payload and the access key in the aeg-sas-key header.
The event is successfully published and routed to the Azure Function.
This initiates the delivery pipeline, transmitting the test event to the registered handler.

Key Concept

Publishing events to a custom Event Grid topic
Rate this question