You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Azure Event Grid is a fully managed event routing service built on a publish-subscribe model. It enables event-driven architectures by connecting event sources (publishers) to event handlers (subscribers) with reliable delivery, filtering, and fan-out. Event Grid is a key building block in Azure serverless architectures, providing the glue between services.
Before diving into Event Grid, it is important to understand the difference between events and messages:
| Characteristic | Event | Message |
|---|---|---|
| Purpose | Notification that something happened | Command or data transfer |
| Content | Lightweight — describes what happened | Contains the full payload |
| Expectation | Publisher does not expect a specific action | Sender expects the message to be processed |
| Coupling | Loose — publisher does not know the subscribers | Tighter — sender knows the receiver |
| Example | "Blob uploaded to container" | "Process this order" |
Event Grid handles events. Service Bus and Queue Storage handle messages. Choose the right service based on whether you are notifying or commanding.
The architecture has four components:
Services that emit events:
| Source | Example Events |
|---|---|
| Azure Blob Storage | BlobCreated, BlobDeleted |
| Azure Resource Manager | ResourceWriteSuccess, ResourceDeleteSuccess |
| Azure Container Registry | ImagePushed, ImageDeleted |
| Azure IoT Hub | DeviceCreated, DeviceTelemetry |
| Azure Event Hubs | CaptureFileCreated |
| Azure Key Vault | SecretNewVersionCreated, CertificateNearExpiry |
| Azure SignalR | ClientConnected |
| Custom topics | Any event you define |
A topic is an endpoint where events are sent:
A subscription connects a topic to a handler with optional filtering:
# Subscribe an Azure Function to blob events
az eventgrid event-subscription create \
--name sub-process-images \
--source-resource-id /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/{account} \
--endpoint /subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Web/sites/{funcApp}/functions/{funcName} \
--endpoint-type azurefunction \
--included-event-types Microsoft.Storage.BlobCreated \
--subject-begins-with /blobServices/default/containers/images/ \
--subject-ends-with .jpg
Services that receive and process events:
| Handler | Description |
|---|---|
| Azure Functions | Execute serverless code in response to events |
| Logic Apps | Trigger a workflow |
| Event Hubs | Stream events for analytics |
| Service Bus | Queue events for reliable processing |
| Storage Queue | Simple queue-based processing |
| Webhooks | Any HTTP endpoint (custom applications) |
| Power Automate | Low-code automation flows |
Event Grid supports two schemas:
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"eventType": "Microsoft.Storage.BlobCreated",
"subject": "/blobServices/default/containers/images/blobs/photo.jpg",
"eventTime": "2024-03-15T10:30:00.1234567Z",
"data": {
"api": "PutBlob",
"contentType": "image/jpeg",
"contentLength": 524288,
"blobType": "BlockBlob",
"url": "https://mystorage.blob.core.windows.net/images/photo.jpg"
},
"dataVersion": "1.0",
"metadataVersion": "1",
"topic": "/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Storage/storageAccounts/mystorage"
}
The CNCF standard schema, increasingly adopted across the industry:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.