Event Grid Event Handlers and Destinations
An event handler is the endpoint that receives and processes events from Azure Event Grid. When an event matches a subscription filter, Event Grid delivers it to the configured handler. The choice of handler determines how the event is processed, stored, or acted upon.
How Event Grid Delivers to Handlers
Event Grid uses HTTP POST requests to deliver events to handlers. Each event or batch of events is sent as the HTTP request body. The handler must respond with an HTTP 200 or 202 status code to confirm successful receipt. Any other response code causes Event Grid to treat the delivery as failed and retry.
Event Grid --> HTTP POST --> Handler Endpoint
(Request Body = event JSON)
Handler responds:
200 OK or 202 Accepted --> Delivery successful
4xx or 5xx --> Delivery failed, Event Grid retries
No response (timeout) --> Delivery failed, Event Grid retries
Handler 1: Azure Functions
Azure Functions is the most commonly used event handler with Event Grid. When an event is published, Event Grid triggers the function directly using an Event Grid trigger binding.
How Azure Functions + Event Grid Works
+─────────────────+ Event +───────────────+ Trigger +──────────────────+
| Blob Storage | ────────────> | Event Grid | ──────────────> | Azure Function |
| (BlobCreated) | | (System Topic)| | (Processes event)|
+─────────────────+ +───────────────+ +──────────────────+
|
Generates thumbnail
Saves to Blob Storage
Azure Function with Event Grid Trigger – Code Example (C#)
[FunctionName("ProcessBlobCreatedEvent")]
public static void Run(
[EventGridTrigger] EventGridEvent eventGridEvent,
ILogger log)
{
log.LogInformation("Event received:");
log.LogInformation(" Type: " + eventGridEvent.EventType);
log.LogInformation(" Subject: " + eventGridEvent.Subject);
// Access the event data
var data = eventGridEvent.Data.ToObjectFromJson<StorageBlobCreatedEventData>();
log.LogInformation(" Blob URL: " + data.Url);
}
Key Points for Azure Functions Handler
- Azure Functions validates the Event Grid subscription endpoint automatically during creation using a handshake challenge
- Functions scale automatically based on event volume
- EventGrid trigger is available in all language runtimes: C#, JavaScript, Python, Java, PowerShell
- Functions can also receive events from Service Bus or Storage Queue if pull-based processing is preferred
Handler 2: Azure Logic Apps
Azure Logic Apps is a low-code workflow service. It provides an Event Grid trigger connector that fires the workflow when a matching event arrives. Logic Apps is ideal for orchestrating multi-step processes without writing code.
Typical Logic Apps + Event Grid Workflow
Event Grid (BlobCreated event) --> Logic App Trigger: "When an Event Grid event occurs" --> Action 1: Send email notification (Office 365 connector) --> Action 2: Create a Teams message (Teams connector) --> Action 3: Update a Sharepoint list item (Sharepoint connector)
Creating a Logic Apps Event Subscription
- Create a Logic App in the Azure Portal
- In the Designer, add the trigger "When an Event Grid resource event occurs"
- Select Subscription, Resource Type, and Resource Name
- Add the desired event types to filter
- Add subsequent actions to process the event
- Save the Logic App — Azure automatically creates the Event Grid subscription
Handler 3: Webhook (Any HTTPS Endpoint)
A webhook is any HTTPS-accessible URL. When Event Grid delivers an event to a webhook, it sends an HTTP POST request to the URL with the event payload in the body. The receiving web server processes the event.
Webhook Validation Handshake
Before Event Grid delivers events to a webhook, it validates ownership of the URL. This prevents malicious actors from directing Event Grid events to endpoints they do not control.
Validation Flow:
Step 1: Developer creates event subscription with webhook URL
Step 2: Event Grid sends a validation request to the webhook URL:
POST https://my-app.com/api/events
Body:
{
"eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
"data": {
"validationCode": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6"
}
}
Step 3: The webhook server responds with the validation code:
HTTP 200 OK
Body: { "validationResponse": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6" }
Step 4: Event Grid confirms validation and starts delivering real events
Webhook Handler – Example (Node.js Express)
app.post('/api/events', (req, res) => {
const events = req.body;
// Handle validation handshake
if (events[0].eventType === 'Microsoft.EventGrid.SubscriptionValidationEvent') {
const validationCode = events[0].data.validationCode;
return res.status(200).json({ validationResponse: validationCode });
}
// Handle real events
for (const event of events) {
console.log('Received event type:', event.eventType);
console.log('Subject:', event.subject);
console.log('Data:', JSON.stringify(event.data));
}
res.status(200).send('OK');
});
Handler 4: Azure Event Hubs
Azure Event Hubs can serve as an Event Grid handler. When Event Grid delivers events to Event Hub, those events enter the Event Hub streaming pipeline. This pattern is useful for collecting large volumes of events from Event Grid and processing them in a stream-processing system such as Azure Stream Analytics or Apache Spark.
Multiple Event Sources
--> Event Grid Topics (with subscriptions)
--> Azure Event Hub (event accumulation layer)
--> Azure Stream Analytics / Azure Databricks
--> Processed insights stored in Azure SQL or Cosmos DB
Handler 5: Azure Service Bus Queue and Topic
Azure Service Bus provides reliable, ordered message delivery. When Event Grid sends events to a Service Bus queue, the events wait in the queue until a consumer application processes them. Service Bus topics support multiple subscribers, each with independent message processing.
When to Use Service Bus as Event Grid Handler
| Requirement | Use Service Bus? |
|---|---|
| Guaranteed ordered processing | Yes — Service Bus sessions support ordered delivery |
| Long-running consumer processing | Yes — messages wait indefinitely until processed |
| Transactional processing (all-or-nothing) | Yes — Service Bus supports transactions |
| Simple, fast event reaction | No — use Azure Functions directly instead |
Handler 6: Azure Storage Queue
Azure Storage Queue is a simple, cost-effective message queue. Event Grid can deliver events directly to a Storage Queue. Consumer applications poll the queue and process events at their own pace. Storage Queue does not support push-based consumption — consumers must poll.
Event Grid --> Storage Queue
|
Consumer App polls queue every N seconds
|
Consumer processes event and deletes message from queue
Handler 7: Azure Relay Hybrid Connections
Azure Relay Hybrid Connections allow Event Grid to deliver events to applications running inside a private network, behind a firewall, or in an on-premises datacenter. The application establishes an outbound connection to Azure Relay. Event Grid then sends events through this tunnel without needing any inbound firewall ports.
Private Network / On-Premises:
+─────────────────────────────────────────────────────+
| |
| On-Premises App <──── Hybrid Connection Tunnel |
| (listens for ────> (established by app) |
| events) |
+─────────────────────────────────────────────────────+
|
Azure Relay (bridge)
|
Event Grid delivers events
Handler Comparison Table
| Handler | Delivery Model | Best For | Code Required |
|---|---|---|---|
| Azure Functions | Push | Serverless code execution | Yes |
| Logic Apps | Push | Low-code multi-step workflows | Minimal |
| Webhook | Push | Custom web applications | Yes (server-side) |
| Event Hubs | Push | High-volume streaming pipeline | No (configuration only) |
| Service Bus Queue | Push to queue, pull by consumer | Reliable ordered processing | Consumer code required |
| Storage Queue | Push to queue, pull by consumer | Simple background processing | Consumer code required |
| Relay Hybrid Connections | Push through tunnel | On-premises or private network apps | Yes (relay listener) |
Summary
Azure Event Grid supports a wide range of event handlers to fit every scenario. Azure Functions and Logic Apps are the simplest choices for serverless processing. Webhooks work for any HTTPS endpoint. Service Bus and Storage Queue add buffering for consumers that cannot keep up with event bursts. Hybrid Connections extend Event Grid delivery to on-premises environments.
