Azure Event Grid (currently in preview) is a managed publisher-subscriber service that pushes events to registered subscribers.
Azure Event Grid does not replace other services such as Azure Service Bus and it has a different focus. Whereas Azure Service Bus might be employed where you need very high reliability, message ordering etc, Azure Event Grid is more about emitting notifications of things that have happened.
Azure Event Grid uses a push model (with some retry logic built in) to push events to subscribers both inside and outside of Azure.
Messages and Events
One way to differentiate when Azure Event Grid may be more appropriate is to think of the publisher’s expectations. Firstly lets use a very general definition of a message as being a single piece of information that is produced somewhere and is (possibly) consumed somewhere. It this case we’re thinking about messages as individual “datagrams” as opposed to an ongoing/continuous stream of data.
If the sender of the message has an expectation when the message is sent we can think of this as a “message with intent”.
If the sender of the message has no expectation of what happens when the messages is sent we can think of this as a “message with no intent”.
For the sake of this article, we’ll call a “message with intent” a command and a “message with no intent” an event. Commands are messages instructing the consumer to do something and that maybe return a result to the sender; events are messages that represent a fact about something that has happened in the system.
Use Case
One use case for Azure Event Grids is to allow easier system extensibility beyond the core business functionality. For example in a sales system new sales leads are captured and stored in a database, this is the core system. This core system could also publish events with no expectation or knowledge about who may be responding to them. An example of an event could be when a new sales lead is added. When the new lead is entered into the core system, a “new-lead” event is published into Azure Event Grid. Now anyone who is interesting in knowing when a new lead has been added can subscribe to this type of event and do something with it.
Azure Event Grid Terminology
An Azure Event Grid event describes what happened in the system represented as JSON data. It contains the custom data specific to the type of event, in addition to information that is contained in all events such as the event source, event time, and a unique event identifier. The full Azure Event Grid event schema is available as part of the docs.
An event source is the place the event happened, for example the sales system, Azure Storage, etc. Event sources publish events. At present the docs list the following supported event sources (with more to be added in the future):
- Resource group management operations
- Azure subscriptions management operations
- Event Hubs
- Storage Blobs
- Custom Topics (HTTP POST-able endpoints)
A topic is an arbitrary categorization of events. Once created, topics have endpoints that event sources publish event to. Events of different types can be sent to the same topic, for example a “sales-leads” topic that holds both “new-lead” and “converted-lead” events.
Event subscriptions wire up topics to event handlers. A topic can have 0, 1, or many subscriptions.
An Event Grid event handler is the place where a subscription sends an event to, for example sending the event using the HTTP webhook event handler. At present the docs list the following Azure event handlers (with more to be added in the future):
- Azure Functions
- Logic Apps
- Azure Automation
- WebHooks
- Microsoft Flow
An event consumer (while not explicitly stated in the docs) can be thought of as the thing that the event handler pushes the event to. The event consumer receives the pushed event and uses it, for example an Azure Function responding to a “new-lead” event and sending out a conference invitation letter/email.
Costs
The cost of using Azure Event Grid is based on usage at the “operation” level with an “operation” being defined as “all ingress events, advanced match, delivery attempt, and management calls”. At the time of writing the preview cost is USD $0.30 per million operations with 100,000 free operations per month. You can find the latest pricing here.
To learn more, check out the Azure Event Grid docs.
If you want to fill in the gaps in your C# knowledge be sure to check out my C# Tips and Traps training course from Pluralsight – get started with a free trial.
SHARE: