Azure Functions programming model
Azure Functions provides a programming model that abstracts away much of the underlying infrastructure. This allows you to focus on writing event-driven code that responds to various triggers and interacts with other services through bindings.
Core Components
Triggers
A trigger defines how a function is invoked. When the event specified by the trigger occurs, the Azure Functions runtime executes your function. Triggers can be based on HTTP requests, timers, messages in a queue, changes in a database, and more.
Bindings
Bindings allow you to declaratively connect your function code to other Azure services or external data sources without writing boilerplate integration code. They come in two main forms:
- Input Bindings: Used to pass data into your function.
- Output Bindings: Used to send data from your function to another service.
Bindings simplify data access, making your code cleaner and easier to manage. For example, you can use a Cosmos DB input binding to retrieve a document or a Queue output binding to send a message to a storage queue.
// Example C# function with HTTP trigger and Blob output binding
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
public static class ProcessQueueMessage
{
[FunctionName("ProcessQueueMessage")]
public static async Task Run(
[QueueTrigger("myqueue-items")] string myQueueItem,
[Blob("output-container/{queueTrigger}.txt", FileAccess.Write)] out string myBlob,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
myBlob = $"Processed message: {myQueueItem}";
}
}
Function App
A function app is the execution unit for one or more Azure Functions. A function app allows you to group functions together for easier management, deployment, and scaling. Functions within the same app share the same execution plan and application settings.
Supported Languages
Azure Functions supports a variety of programming languages, including:
- C#
- JavaScript
- TypeScript
- Python
- Java
- PowerShell
- TypeScript
You can choose the language that best suits your project requirements.
Execution Context
When your function is triggered, the runtime provides an execution context. This context typically includes information about the trigger event (e.g., HTTP request details, queue message content) and logging utilities.
Next Steps
Explore the following resources to learn more: