Page 26 - MSDN Magazine, February 2018
P. 26
Topics
Event Subscriptions
If a message is published without any knowledge or expectations of how it will be handled, then it’s deemed to be an event. Let’s say that within an organization, the same employee has requested to change their mailing address. Because this action might be interesting to many systems in the organization but doesn’t require the publisher to specifically be aware of any of them, it’s a message that doesn’t define any intent. In this case, the pub- lisher is simply notifying any interested parties that an event has occurred. It’s an event, and clearly an occurrence of something that’s a viable option for a service like Event Grid.
Blob Storage Resource Groups Azure Subscriptions Event Hubs
Custom Topics
Event Publishers
Figure 3 Azure Event Grid Overview
Azure resources are built in and completely transparent to users while custom topics are provisioned ad hoc and exist in a resource group. Event subscriptions are simply associated with a topic. This model simplifies management of topics as subscriptions and makes Event Grid highly multi-tenant, allowing for massive scale out.
Azure Event Grid is agnostic to any language or platform. While it integrates natively with Azure services, it can just as easily be leveraged by anything that supports the HTTP protocol, which makes it a very clever and innovative service.
Events or Commands
Before I dive into some code and build out a solution that high- lights some of these features, lets distinguish between an event and a command. The distinction can sometimes be subtle, but it’s import- ant to comprehend when designing systems that rely on messages.
When a message is sent a specific action or response, it’s most likely a command. For example, if an employee is promoted within an organization and a message is sent to instruct his new manager to fill out a form, then it carries with it a specific purpose or intent. Because the sender of the message has an expectation, and in some cases, might even expect a response, we can categorize this as a command.
Azure Functions Logic Apps
Azure Automation WebHooks
Event Handlers
New Employee Welcome
New Employee Equipment Order
Employee Records System
I can spend a lot more time discussing these distinctions and in addition how to select the appropriate messaging service on Azure, however, that’s out of the scope of this article. I encourage you to read this insightful post from Clemens Vasters on the topic: bit.ly/2CH3sbQ.
A Human Resources Scenario
The best way to get a deeper understanding of Event Grid is by writing code that leverages its capabilities. In this article, I’ll look at a few events that originate from a fictitious HR application. I’ll publish events to a custom topic and then subscribe to the events using several different handlers.
When a message is sent a specific action or response, it’s most likely a command.
To keep things simple, I’ll be implementing two types of events from the HR system—when an employee is added to an organiza- tion and when an employee is removed. These events are close enough in nature that it will provide options that showcase how to filter and handle events in diverse ways. A visual representation of the solution
HR Application
Employee Events
Welcome Email
Queue Order
Update Records
is illustrated in Figure 4.
At a high-level, the solution consists of several
key components that I will build in this article. Let’s explore them here.
Employee Events will be an Event Grid Topic to which the HR application can send messages. This will include events for new and removed employees in the organization. Each message will contain information about the employee, her department and the type of event.
New Employee Welcome will be a Logic App that subscribes to messages for new employees in the organization. It will ultimately send a welcome email to the new employee.
Microsoft Azure
Figure 4 A Sample Solution 22 msdn magazine