Jak skonfigurować i używać sieci Azure Event Grid dla architektury opartej na wydarzeniach
Wprowadzenie to do Azure Event Grid
Azure Event Grid is a fully managed even event routing services that they backbone for event-drift architectures in the cloud. It enenables different condigents of an application - whether they ary Azure services as, custem applications, or third-party systems - to communicate asynchronously by publishing andabonbing to events. Thi decoupling als systems to be more conficient, scalable, and responsive te te te te te te changes in real time.
In this guides, we will walk through gh the complete process of setting up and using Azure Event Grid. You will learn how to create topics, configuration a solid d foundation for building event- direcognity solutions in Azure.
Understanding Event- Driven Architectures
Traditional request-response architectures of ten create intrict coupling between services. When one services needs to notify others of a change, it mutt know when e each receiver is and how to call them. Thit leads to complex dependencies and brittle integrations. Event- context architectures solve this by proveling an intermediary - then event broker - that manages thee routing of events from producertas subscribers. Producers events to a tout withit intainf whinf will, them, and subscrimes, anvestér interess en events events events.
Azure Event Grid excels in this role because it is designed for massive scale and reliability. It supports both system events (like blob storage creation or resource group changes) and custorem events frem your own applications. The service automatically handles retries, dead-lettering, and filtering, so you can focus on contess logic rather than infrastructure plumbing.
Key Concepts of Azure Event Grid
Events
An event is a small piece of data that describes what happed. Each event contains a subit, event type, event time, and a data payload. For example, a storage account creation event might have thee subit 1; Event 3; FLT: 0 event 3; and event type behaftude 1; FLT: 1 erend 3; Events follow theme schema structure.
Tematy
A topic is an endpoint when e events are sent. It providees a namespace for events of a certain category. You can create system topics for Azure resources (like a storage account or resource group) or custom topics for your own applications. Topics are regional resources, so you mutt choose a region during creation.
Event Subscriptions
Subscriptions definiuje dlaczego subskrybenci chcą subskrybenta to receive and how they should be delivered. You can filter events based on sub, event type, or data fields. Subscripts also deceify thee endpoint type - condin options including de webhooks (HTTP endpoints), Azure Functions, Event Hubs, Service Bus queuees or topics, and Azure Logic Apps. Each subskryption have its own retry policy and demetter destinationinon.
Event Publishers
Any service or application that sends events to an Event Grid topic is a publisher. Publishers don 't need to know about subscribers; they simple poste events to thee topic endpoint. Azure SDKs, REST API, and CLI are revacable for publishing events.
Event Handlers
Te event handler is thee contesent that processes thee incoming event. Azure Event Grid supports several handler type: webhooks that respond to HTTP POST, Azure Functions, Automation runbook, Logic Apps, andd more. For webhooks, Event Grid requises a handshake te validate the endpoint before events are delivered.
Step- by- Step Setup of Azure Event Grid
Let 's go the practical steps to set up Azure Event Grid, frem creating a topic tu subskrybbing and d publishing events.
1. Stworzenie a Event Grid Topic
Navigate te Azure portal (reviden1; FLT: 0, 3; PRI3; PRI3; PRIV.azure.com presenta1; PRIVE 1; FLT: 1, 3; PRIVE 3;) and search clush for context; Event Grid. context; Click British 1; PRIVE 1; FLT: 2, PRIV3; Create British 1; PRIV1; FLT: 3, PRIV3; And secose Britionate 1; FLT: 4, PRIV3; Topitions; FLIC 3; FRIC 3; FRM the options. You will need to provide:
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Subscription Xi1; Xi1; FLT: 1 Xi3; Xi3;: The Azure subscription undeir which the topic will be created.
- W przypadku gdy w ramach projektu nie ma już żadnych innych środków, należy podać, czy dany projekt jest zgodny z wymogami określonymi w art. 3 ust. 1 lit. a) rozporządzenia (UE) nr 1303 / 2013.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Name Xi1; Xi1; FLT: 1 Xi3; Xi3;: A globally unique name for the topic. This becomes part of the endpoint URL.
- W przypadku gdy w wyniku zastosowania środka nie można zastosować środka przejściowego, należy podać, czy jest to konieczne, czy nie.
Opcjonalne, you can enable system- assigned managed identity or add tags for governance. After validation, click amend1; erend1; fLT: 0 memorial 3; event1; event1; event1; fLT: 1 metrid3; event3; event3. thee deployment takes a minute or two. once ready, you will see thee topic endpoint URL and an accorses key or SAS token in thee topic 's accort quet; section.
2. Stworzenie an event Subscription
With thee topic created, you need at t leaaset one subscription to receive events. In the topic 's overview page, click indiv1; endi1; FLT: 0 contribution 3; endiv3; + Event Subscription indiv1; endi1; FLT: 1 contribution 3; endiv3. provide:
- Xion1; Xion1; FLT: 0 Xion3; Xion3; Name Xion1; Xion1; FLT: 1 Xion3; Xion3;: A descritive name for the subscription.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Event Schema Xi1; Xi1; FLT: 1 Xi3; Xi3;: Choose between Event Grid schema or CloudEvents v1.0 schema. CloudEvents is Xiling thee industry standard for Xisability.
- Xi1; Xi1; FLT: 0 XI3; XI3; Endpoint Type Xi1; XI1; FLT: 1 XI3; XI3; FLT: Select the type of handler. For testing, choose Xi1; XI1; FLT: 2 XI3; XI3; VI1; FLT: 1; FLT: 3 XI3; XI3; And provide the URL of your endpoint. For production, you might use ain Azure Function or Logic App.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Filtry Xi1; Xi1; FLT: 1 Xi3; Xi3;: You can enable filtering on event type, sub begins / ends with, or advanced filters (np., data fields). This reduces unwanted events reaaching your handler.
- Retry Policy Sig1; Retry 1; FLT: 1 Sig3; Embl3; Set the maximum number of delivery delicts andd time- to- live for events. Default is 30 days and4 retries.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Dead- Lettering Xi1; Xi1; FLT: 1 Xi3; Xi3;: Specify a storage blob container where undeliverable events are sent after excludusting retries. This is critical for debugging andd reliability.
Click present 1; Sig1; FLT: 0; Sig3; Create precendence 1; Sig1; FLT: 1 Sig3; Sig3; If you chose a webhook endpoint, Event Grid will send a validation request. Your endpoint mutt respond witt a validation code (often part of te handshake process) to confirm ownership. Once validated, events will flow.
3. Publishing Events
To publish events, you need the topic endpoint URL and an accessis key or SAS token. Thee event payload mutt follow the indic1; indic1; FLT: 0 contribution 3; envent Grid schema indic1; endic1; entis1; FLT: 1 contribution 3; indic3;. Here is a minimal example using thee Azure CLI:
az eventgrid event submit \
--endpoint https://your-topic.westus-1.eventgrid.azure.net/api/events \
--subject "custom/test" \
--event-type "MyApp.NewRecord" \
--data '{"id":123,"name":"test"}' \
--key aabbccdd...
You can also use REST API, PowerShell, or SDKs (C #, Python, Java, Node.js). For serverless environments, Azure Functions can publish events via an output binding.
4. Handling Events wigh Azure Functions
One of thee most combn wzocts is to use an Azure Function as an event handler. Create a new Azure Function App andd add an Event Grid trigger. The functionion will receive events as JSON. Here 's a simple C # example:
[FunctionName("ProcessEvent")]
public static void Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
{
log.LogInformation($"Received event: {eventGridEvent.EventType} with subject {eventGridEvent.Subject}");
// Process the event data
}
Te funkcjonalne runtime automatically validates thee webhook handshake if you use Event Grid trigger binding. This approach gives you a scalable, serverless event procesor.
Advanced Scenariusze i wzory
Beyond basic setup, Azure Event Grid supports experimentated architectures. Here are several advanced us case:
Filtering andRouting
Use advanced filtering to route events based on data values. For example, you might have a topic that receives events frem multiple departments. You can cant separate subscriptions for quentile quentit; HR quentile quentil; events (filter on presents 1; flT: 4 contributions 3; flT exceptive quent; events. Thi ensures each handler only processes contribulent events, reducing load and simplifying logic.
Event Grid Domains
When you need to manage many topics for different tenants or applications, Event Grid Domains provide a hierarchical namespace. Each domayn can contain multiple topics, and you can appety policies, authentiation, and monitoring at te domail level. This is ideal for SaaS providers who offer event services multiple customers.
Hybrid and- Multi- Cloud Integration
Event Grid can connect to external systems using webhooks. You can send events to on- premises systems via combird connections, or tu tec other cloud providers using public HTTP endpoints. For security, use managed identities andd SAS tokens to authentivate outgoing calls. Also, consider using Azure Arc to manage on- premises resources with Event Grid.
Integration with Azure Logic Apps
Logic Apps can consume Event Grid events a trigger, enabling low-code workflows. For example, when a new blob is created in storage, a Logic App can automatically copy it to anotherr location, send an email, or update a datase. Thee visaal designer makes itt easy to build d complex orchestrations with out writing code.
Bett Practices for Production Deployments
Tu ensure your Event Grid solution is reliable, secre, and cost- effective, follow these best praktyces:
- Reg. 1; Reg. 1; FLT: 0; FLT: 0; Ar. 3; Always enables dead- lettering pret1; An. 1; FLT: 1; At. 3;. Without it, undelivered events are silently dropped after reties. A dead- letter destination (blob storage) helps you diagnose delivy defeures and reprocess events if needed.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Usie managed identities for authentiation Xi1; Xi1; FLT: 1 Xi3; Xi3. Instad of storing keys, enable managed identity one your publisher (e.g., an Azure Function) and grant it permissionon to publish tu the topic. For subscribers, use managed identities to avoid key management.
- Xion1; Xion1; FLT: 0 Xion3; Xion3; Leverage filtering at thee subscription level Xion1; Xion1; FLT: 1 Xion3; Xion3;. Thii reduces the number of invocations on your handlers, saving cocht and improwing performance. Use advanced filters for fine- grained control.
- Because Event Grid diffices at leaste once delivy, your handler may receive thee same event multiple times. Ensure your processing logic can e handle duplicates gracefuly (e.g., by checking a unique event ID or using a déplication story).
- Xiv1; Xi1; FLT: 0 XI3; XI3; XI1; XI1; FLT: 1 XI1; FLT: 0 XI3; FLT: 0 XI3; XIX3; XIX3; XIXL; XIXL; XIXL; XIXL; XIXL: XIXL; XIXL: XIX1; FLT: 0 XIX3; FLT: 0 XIX3; XIXL; XIXIXIXL; XIXIXIXIXL; XIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXIXYYYYYYYYYYYYYYYYY@@
- Recovery 1; FLT: 0 is 3; FLT: 0 is 3; FLT: 0 is 3; FLT: 0 is 3; FL3; PLAN for geo- disaster recovery i1; PLAN for geo- disaster recovery 1; FLT: 1 is 3; FLT: 1 is 3; FLT: 0 is regional. If you need global dicourence, deploy topics in multiple regions and use a custim routing mechanism. Consider using Azure Event Grid 's partner events or cros- region replication for criticail dicolos.
- Referencje dotyczące URL or ID in then event, ande let thee handler fetch additional data from a repositorie.
Kwestie bezpieczeństwa
Security in event- drivn systems has several layers:
- Reference 1; Reference 1; FLT: 0 (0) 3; Reference 3; Anse (0); Ansentication for publishers (1); FLT: 1 (3); FLT: 0 (3); FLT: 0 (3); Anse (3); FLT: 0 (3); Anse (3); Anse (3); Ansention For publishers; Ansentioon; FLT: 1 (3); FLT: 1 (3); FLT: 0 (3); FLT: 0 (3); FLT: 0 (3); FLT: 0 (3); FLT: 0 (3); FLS: 0 (3); FLS: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0: 0:
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Endpoint validation for subskrybents Xi1; Xi1; FLT: 1 Xi3; Xi3;: When using webhooks, Event Grid sends a validation handshake to confirm the subskryber controls thee endpoint. Your webhook must respond appropriately tu avoid unautrized event forwarding.
- W przypadku gdy w wyniku kontroli na miejscu nie ma żadnych dowodów na to, że nie można uznać, że w przypadku braku kontroli na miejscu, w przypadku gdy nie jest to możliwe, należy zastosować odpowiednie środki ostrożności.
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; Data critiption Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3; FLT: 0 Xiv3; Xiv3; Xiv3; Data critiption Xiv1; Xiv1; FLT: 1 XIV3; XIV3; XIVE are critipted at rest rett andin transit (TLS 1.2 +). You can also bring youk own key (BIOK) for additional control over cription keys.
Cost Management
Azure Event Grid pricing is based on thee number of operations (published events and delivery delites) and the e number of topic / subscription resources. Tu optimize costs:
- Łączenie wielu typów event typu into a single topic and filter at thee subscription level. This reduces the number of topics needed.
- Usie event filtering aggressively to avoid unnecesary deliveries. Each delivy counts as an operation.
- Leverage Event Grid Domains for multi- tenant considios - they share infrastructurte and can be cheaper than separate topics.
- Set appropriate retry policies. The default retries (30 days) may be too long; adjuss the time-to- live and max retries based on your SLA.
Monitoruj your usage via Azure Cost Management and set budgets or alerts to avoid unexpected bills.
Monitoring andd Troubleshooting
Azure Monitoror provides conclussive metrics for Event Grid. Key metrics include:
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; Publish Succeeded Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3;: Number of events successfuly published.
- VII.1; VII.1; FLT: 0 VII3; VII3; Publish VII3d; VII1; VII1; VII3; VII3; VII3d; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIId; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIIe; VIId) VIId) VIId) VIId; VIIe; VIIe; VIIe; VIIe; VIIe; VII.VII.VII.VII.VII.VII.VII@@
- Relivery Succeeded Reliance (FLT): 1 Reliance 3x3; FLT: 0 Reliance 3; FLT: 0 Relivery 3; Delivery Succeeded Relivery 1; FLT: 1 Reliance 3; Events succeefuly deliveid to subskrybers.
- Reference: 1; Delivery Delived Delivery Delived Deliver1; Deliver1; FLT: 1 Deliver3; Deliver3; Events that nt be delivered (np., endpoint nott reachable).
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Dead Lettered Xi1; Xi1; FLT: 1 Xi3; Xi3;: Events that execusted retry Xits.
You can also enable diagnostic logs for thee topic and subscription. Logs capture details about each publish and delivery operation, including error codes and latency. Usie Log Analytics queries to correlate failures with specific event types.
Common troubleshooting steps:
- If events are nott reaching your handler, check the subscription endpoint health. Use the quentiquette; tett quentiquetten; capability in thee portal to send a sample event.
- If validation failes for a webhook, ensure your endpoint returns HTTP 200 with thee validation code. For Azure Functions, thee binding handles this automatically.
- If events are being dead- lettered, inspect the dead- letter blob container for thee original event payload andd error details.
Integration wigh Other Azure Services
Azure Event Grid pracuje natively with many Azure services. Here are a few contron integrations:
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; Azure Blob Storage Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3; FLT: 0 Xiv3; Xiv3; Xiv3; Xiv3; Azure Blob Storage Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3; Xiv3;:: Automatically sends vents when blobs are created, deleted, or updated. Useful for triggering processing ging contrivalines.
- React to build completions, pull request events, and more te automate CI / CD.
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; Azure Machine Learning Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3;: Trigger retraining jobs or deployment Xivines when new data arrives.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Azure IoT Hub Xi1; Xi1; FLT: 1 Xi3; Xi3;: Route device telemetry andd lifecycle events to downstream procesing.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Azure Kubernetes Service (AKS) Xi1; Xi1; FLT: 1 Xi3; Xi3;: Usie Event Grid to Watch AKS events for cluster autoscaling or application deployment.
Te power of Event Grid lies in it s ability to connect these dispate services with minimal code.
Real- Worlds Example: Serverless Order Processing
Imaginane an e-commerce platform that processes orders. When a customer places an order, thee web app publishes an event to an Event Grid topic: inde1; ende1; FLT: 5 contex3; index3; with data like order ID, customer info, and items. Three subscriptions are configured:
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; Inventory Service Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3; (Azure Function): Reserves stock andd updates Inventory datase.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Payment Service Xi1; Xi1; FLT: 1 Xi3; Xi3; (Logic App): Processes payment via a third-party gateway.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Notification Service Xi1; Xi1; FLT: 1 Xi3; Xi3; (Webhook to SendGrid): Sends confirmation email to the customer.
Each subscription filters by even type andsumit, so they only receive relevant events. If thee payment services fairs, retries are delited; after exclusive te event is deadly-lettered for manual intervention. Thee entire system is decouppled: thee web app doesn 't need to know about thee downstream services. New services can by added later by simplity concreation a new subscription.
Ograniczenia i alternatywy
While Azure Event Grid is powerful, it has some consilints:
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Event size limit Xi1; Xi1; FLT: 1 Xi3; Xi3;: Maximem event size is 1 MB (including headers). For larger payloads, use a reference te blob storage.
- Reg.
- Xi1; Xi1; FLT: 0 Xi3; Xi3; Ordering Xi1; Xi1; FLT: 1 Xi3; Xi3;: Event Grid does nots contribue per- topic ordering; events may arrive out of order. If ordering is critical, use Event Hubs or Service Bus.
- Xiv1; Xiv1; FLT: 0 Xiv3; Xiv3; At- least- once delivy Xiv1; Xiv1; FLT: 1 Xiv3; Xiv3;: Duplicate delivy is possible. Handlers must be idempotent.
Choose Azure Event Grid when you need a simple, serverless event router with pub / sub semantics. For event streaming or ordered delivery, combinane it with tell Azure messaging services.
Konkluzja
Azure Event Grid is a foundationol services for building modern event-dropn applications in thee cloud. By decoupling producers from consumers, it enables architectures that are scalable, dimenent, and easyy to extend. Setting it up involves creating a topic, one or more subscriptions, and a handler to process events. Bess practiones like deadly-lettering, filtering, idepotent handlers, and moning ensure production readiness.
Whether you are e automating infrastructures, connecting microservices, or building a real-time notification system, Event Grid provides a robust, cost- effective even routing layer. Start small, embrace thee event- conduct mindset, and gradually expand your message- based workles. Thee explicbility and integration with the larger Azure ecosystem make Event Grid a go- to choice for developers and architectes alike.
For further reading, exploore the official ail 1; Xi1; FLT: 0 Xi3; Xi3; Azure Event Grid documentation Xi1; Xi1; FLT: 1 Xi3; Xi3; and the e Xi1; Xi1; FLT: 2 Xi3; Xi3; Event schema reference XiVe; XiV1; FLT: 3 XiV3; XiV3; FLT: 3; XiViVE;