Event handlers

Event handlers are programs or functions that are executed in response to a specific event. A good example of event handlers, also known as event listeners, would be webhooks reacting to an event raised from an application, or JavaScript responding to user input through a graphical UI:

<form action="#" method="post"> 
<input type="button" value="Display Message" onclick="window.alert('Hello world!');">
</form>

In Microsoft Azure, multiple products and services support eventing, including Cosmos DB, Azure Resource Group, Azure Storage, and others. To understand events in Azure, let's look at the following example of an Azure Function reacting to a Cosmos DB change feed. This Function reacts to any object change in Cosmos DB and posts the change feed request to the external web URL:

[FunctionName("CosmosFeed")]
public static async System.Threading.Tasks.Task RunAsync([CosmosDBTrigger(
databaseName: "socialwikigraph",
collectionName: "sample01",
ConnectionStringSetting = "CosmosDBConnection",
CreateLeaseCollectionIfNotExists = true,
LeaseCollectionName = "leases")]IReadOnlyList<Document> documents, TraceWriter log)
{
if (documents != null && documents.Count > 0)
{
log.Verbose("Documents modified " + documents.Count);
log.Verbose("First document Id " + documents[0].Id);

var jsonString = JsonConvert.SerializeObject(documents);
var content = new StringContent(jsonString, Encoding UTF8, "application/json");

var response = await client PostAsync("https://webhook.site/9d2ae6bf-cd79-4896-b44c-0e60a9e2061a", content);
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.211.231