Created
February 1, 2019 18:59
-
-
Save JeremyLikness/4b0218cf984c7ea5bfbb1e78bb654421 to your computer and use it in GitHub Desktop.
Receiving an event grid event
This file contains hidden or 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
[HttpPost] | |
public IActionResult Post([FromBody]EventGridEvent[] value) | |
{ | |
if (value == null || value.Length != 1 || value[0].Data == null) | |
{ | |
_logger.LogError("Bad event."); | |
return BadRequest(); | |
} | |
_logger.LogInformation($"Received event with type {value[0].EventType}"); | |
if (value[0].EventType == "Microsoft.EventGrid.SubscriptionValidationEvent") | |
{ | |
var subscriptionValidation = value[0].Data.ToObject<SubscriptionValidationEvent>(); | |
_logger.LogInformation($"Validating subscription with token {subscriptionValidation.ValidationCode}"); | |
return Ok(new SubscriptionValidationResponse | |
{ | |
ValidationResponse = subscriptionValidation.ValidationCode | |
}); | |
} | |
_logger.LogInformation($"Parsing payload {value[0].Data}..."); | |
var msg = value[0].Data["message"].ToString(); | |
_logger.LogInformation($"Received message: {msg}"); | |
return Ok(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment