Page 28 - MSDN Magazine, September 2018
P. 28

deadletterchannel.YoucanuseatoollikeAzureStorageExplorer Getblobcontentusingpathistheactionthatwillreadthecon-
to see the new blob that’s created for each dead-lettered message. However, that isn’t very exciting. As an alternative, I want to be notified when a new message is added to the dead letter channel.
Inspecting Dead Letter Events
Because the dead letter event is just a new blob created in a con- tainer, Event Grid can be used to kick off another workflow that’s triggered when the file is created. Figure 5 demonstrates the work- flow for how an event can originate from a storage account and ultimately be received by a Logic App and send an email.
The only thing I’ll need to put this together is a Logic App that begins with an Event Grid trigger. The first three steps in the application comprise the following actions and trigger:
Event Grid trigger is configured for the storage account. It uses two filters—one for the event type (Microsoft.Storage.BlobCreated) and the second for the container using the prefix filter option. Both of these filters ensure that the app is only invoked when a new file is created within the dedicated dead letter container.
Initialize variable is the next action that retrieves the URL from the body of the Event Grid message. Its value is the following expression:
triggerBody()?['data']['url']
tents of the blob. I format the value of the blob path using this string manipulation expression to remove the portion that isn’t needed:
replace(variables('DeadLetterUrl'), 'https://<storage-account-name>.blob.core.windows.net', '')
These initial steps are shown in Figure 6.
Here are the final actions of the Logic App:
Parse JSON will evaluate the contents of the blob and pro-
vide a set of variables I can reference later. The expression for the Content property is:
json(body('Get_blob_content_using_path'))
I’ll also need to provide a sample payload that looks like:
[{
"id":"100", "eventTime":"2017-08-21T06:42:20.0000000+00:00", "eventType":"type",
"dataVersion":"",
"metadataVersion":"1",
"topic":"enpoint",
"subject":"testsubject", "deadLetterReason":"reason", "deliveryAttempts":1, "lastDeliveryOutcome":"BadRequest", "lastHttpStatusCode":400, "data":{"something":"data"}
}]
Send an email is the last action, which formats the body and subject of the email with the artifacts of the events (dead letter reason and subject). Because the payload actually contains an array, Logic Apps recognizes that and wraps
the action in a for each action.
As a side note, each step within a for
each loop is done in parallel instead of sequentially in Logic Apps; this is the default behavior that can be changed to run sequentially, if desired. The end result is displayed in Figure 7.
Testing this end-to-end will result in an email being sent for each dead letter event.
Wrapping Up
With its original design and deep integration into a growing list of Azure services, Event Grid is only beginning to reveal innovative ways to build event-driven solutions. In this article, I demonstrated how to leverage the new retry policies and dead lettering func- tionality in Azure Event Grid. These highly anticipated features are powerful options for making solutions built on Event Grid more resilient and scalable. The code in this arti- cle can be found at bit.ly/2LGKjhN. n
DaviD Barkol is an Azure specialist at Microsoft on the Global Black Belt Team. You can contact him on Twitter: @dbarkol or through email at dabarkol@microsoft.com. He blogs regularly about Event Grid at madeofstrings.com.
Thanks to the following Microsoft technical expert for reviewing this article: Bahram Banisadr
Azure
Figure 7 Parsing JSON and Sending Notifications 20 msdn magazine


































































































   26   27   28   29   30