Validating an HTTP Endpoint to Obtain Occasions from Azure Occasion Grid
Introduction
This text explains learn how to confirm an HTTP endpoint earlier than receiving and deserializing occasions from an occasion subscription.
Stipulations
To validate an HTTP endpoint to obtain occasions from Azure Occasion Grid, you may certainly have to create an Azure Perform App with an HTTP-triggered perform.
Endpoint Validation
You need to maintain Microsoft.EventGrid.SubscriptionValidationEvent associated to subscription validation. Occasion Grid sends a validation occasion to the endpoint with a validation code within the knowledge payload every time an occasion is subscribed to. To confirm that the endpoint is justified and yours, it should amplify this again within the physique of the response. To deserialize a Binary Knowledge occasion containing a number of occasions into an array of EventGridEvent, use the ParseMany() methodology. You might use the Parse methodology rather than deserializing a single occasion when you had been conscious prematurely.
Use the next code to programmatically amplify the validation code.
///
/// EventIntake Perform.
///
/// The Req.
/// The Log.
/// Returns Response Code.
[FunctionName("EventGridFunction")]
public async Job EventIntake(
[HttpTrigger(AuthorizationLevel.User, "post", Route = null)]
HttpRequest req, ILogger log)
attempt
BinaryData occasions = await BinaryData.FromStreamAsync(req.Physique);
log.LogInformation($"Obtained occasions: occasions");
EventGridEvent[] eventGridEvents = EventGridEvent.ParseMany(occasions);
var validationEvent = eventGridEvents.FirstOrDefault(x => x.EventType == "Microsoft.EventGrid.SubscriptionValidationEvent");
if (validationEvent != null)
var validationData = validationEvent.Knowledge.ToObjectFromJson();
var validationResponse = new
ValidationResponse = validationData.ValidationCode
;
log.LogInformation("Obtained Validate Subscription occasion. Echo again the validation code code", validationResponse.ValidationResponse);
return new OkObjectResult(validationResponse);
// Your Logic
return new OkObjectResult(string.Empty);
catch (Exception e)
log.LogError(e, "Unable to cross occasion grid message");
return new BadRequestObjectResult(e);
Take a look at Validation Response
Copy and paste the pattern occasion into the perform’s check subject to check the validation response perform.
[
"id": "21915976-38b1-449d-8edf-a406ee6d23e5",
"topic": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"subject": "",
"data":
"validationCode": "6179467e-fefb-43c3-b92f-67370daedf99"
,
"eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
"eventTime": "2018-01-25T22:12:19.4556811Z",
"metadataVersion": "1",
"dataVersion": "1"
]
Conclusion
By following the rules offered on this article, you may successfully confirm HTTP endpoints earlier than receiving and deserializing occasions from occasion subscriptions, enhancing the safety and reliability of your event-driven structure in Azure Occasion Grid.
Know extra about our firm at Skrots. Know extra about our companies at Skrots Companies, Additionally checkout all different blogs at Weblog at Skrots
Know more about our company at Skrots. Know more about our services at Skrots Services, Also checkout all other blogs at Blog at Skrots
Thanks, Harsh
Founder | CEO — Skrots
Learn more about our blog at Blog at Skrots. Checkout our list of services on Skrots. Give a look at our website design at Skrots . Checkout our LinkedIn Page at LinkedIn.com. Check out our original post at https://blog.skrots.com/validating-an-http-endpoint-to-receive-events-from-azure-event-grid/?feed_id=3977&_unique_id=65c43ce76615b