Last active
December 31, 2018 13:38
-
-
Save PradeepLoganathan/23894ddc84ae42be55bf8cacea5f68be to your computer and use it in GitHub Desktop.
Azure Event grid - Custom event handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<IActionResult> Post([FromBody]object request) | |
{ | |
try | |
{ | |
var eventGridEvent = JsonConvert.DeserializeObject<EventGridEvent[]>(request.ToString()); | |
foreach (var item in eventGridEvent) | |
{ | |
if (string.Equals(item.EventType, "Microsoft.EventGrid.SubscriptionValidationEvent", StringComparison.OrdinalIgnoreCase)) | |
{ | |
var data = item.Data as JObject; | |
var eventData = data.ToObject<SubscriptionValidationEventData>(); | |
var responseData = new SubscriptionValidationResponse | |
{ | |
ValidationResponse = eventData.ValidationCode | |
}; | |
return Ok(responseData); | |
} | |
else | |
{ | |
await DoSomethingWithEvent(item.Data.ToString()); | |
} | |
} | |
} | |
catch (Exception ex) | |
{ | |
telemetry.TrackException(ex); | |
throw; | |
} | |
return Ok(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment