Azure Event Grid Filters

In this post I’m taking a deeper look at Azure Event Grid filters and using them in Azure Logic Apps. Take note that Azure Event Grid was in preview at the time of writing and there were a few hiccups.

Event Data Schema

I used this quickstart from the Azure team as a base. It used this JSON file for the event data.

[
 {
 "id": "'"$RANDOM"'",
 "eventType": "recordInserted",
 "subject": "myapp/vehicles/motorcycles",
 "eventTime": "'`date +%Y-%m-%dT%H:%M:%S%z`'",
 "data":{
 "make": "Ducati",
 "model": "Monster"
 }
 }
]

You can read the full schema documentation here. The id, eventType, subject and eventTime properties are required and most of them are used internally by Azure Event Grid. The data object is for your custom data and can be any JSON object.

Filters

An event subscription can contain prefix, suffix and event type filters.

 

 

 

 

 

 

 

 

 

The event type filter will filter on the eventType property. You can add multiple event types separated by a semi colon, wild cards do not work.The prefix and suffix filters will filter on the subject property. You cannot add multiple values in a prefix or suffix filter and wild cards do not work.
Side Note: The Prefix filter was read only in the Azure portal when I tested it but you could set it using the Azure CLI.

az eventgrid topic event-subscription create --name eventsubprefic --endpoint https://requestb.in/1fy6fab1 -g gridResourceGroup --topic-name testtopic5765 --subject-begins-with test

You can read the full event subscription schema here.

Using Azure Event Grid In A Logic App

I used the quick start example here as a base and used the SendGrid connector to notify me of events in a resource group. At the time of writing Azure Event Grid was still in preview so there will be some problems which are pointed out in the documentation. You have to login with an Azure Directory user or use a Service Principal connection for the Azure Event Grid connector in the Logic App designer. If you use a Microsoft live account it won’t be able to connect to Azure.

I also had a problem accessing all the event properties in the dynamic content window, the body wasn’t showing for instance. To work around it, switch to the expression editor and start typing the property names to see the full list. Now you can switch back to the dynamic content window and select the properties you want in the email body.

 

 

 

 

 

 

 

 

 

You can apply prefix and suffix filters by clicking on Show advanced options but not on the eventType.

 

 

 

 

 

 

 

 

If you have a requirement to filter on other properties you can do it by adding a condition statement and writing some code. The quick start I mentioned earlier shows exactly how to do this.

Francois Delport

Azure Event Grid Explained

In this post I’m going to have a look at Azure Event Grid which recently entered public preview. This is a summary I put together to wrap my head around it after reading the official documentation.

First Some Terminology

  • Event Publisher – The application/service/component raising the event.
  • Event Handler –  The end consumer of the event.
  • PubSub pattern – Azure Event Hub implements the Publish-Subscribe message pattern, link here. The main benefit of this pattern is loose coupling between publishers of events and the clients consuming them. In other words the publisher of an event doesn’t have to know about each consumer of the event.
  • Topic – The endpoint for event publishers to send their events to and also the endpoint for event subscribers to subscribe to events. Also provides security, message filtering and reliable delivery.
  • Event Subscription – The mechanism used to distribute events to registered event handlers.

What does it do

Azure Event Grid is a managed event routing service. It uses a publish-subscribe model to register client web endpoints with a publisher to receive events. It is aimed at but not limited to serverless applications with built in support in Azure Functions and Azure Logic Applications. That said it supports custom events as well and any web URL can be registered as a webhook to receive events. It is built on Service Fabric to provide scalability and resilience transparently to the end user.

How does it work

Event publishers and event handlers to subscribe to a Topic. The Topic will provide the endpoint for event publishers to sent their events to and event handlers to register to receive events. The mechanism that connects event handlers to the specific events they want to handle is the Event Subscription. The Event Subscription contains the URL to the event handler which it will invoke when a matching event occurs. Event Subscriptions can filter events by type, prefix filter or suffix filter. You can add multiple strings in the filter fields by separating them with a semi colon.

Azure Event Grid

If you look at this sample event used in the quick start, you will see the eventType field used for the type filter.

Azure Event Grid

 

 

 

 

Azure Event Support

At the time of writing Azure Event Grid already exposed some Azure events like Resource Group and Subscription CRUD events. You will find them in the Event Subscriptions blade in the Azure Portal.

Azure Event Grid

Azure Logic Apps also comes with a connector for Azure Event Grid.

Azure Event Grid

Francois Delport