Azure Functions 简介Introduction to Azure Functions

Azure Functions 是一种无服务器解决方案,可以使用户减少代码编写、减少需要维护的基础结构并节省成本。Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. 无需担心部署和维护服务器,云基础结构提供保持应用程序运行所需的所有最新资源。Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running.

你只需专注于对你最重要的代码,Azure Functions 处理其余代码。You focus on the pieces of code that matter most to you, and Azure Functions handles the rest.

我们通常会构建系统来应对一系列的关键事件。We often build systems to react to a series of critical events. 无论是要构建 Web API、响应数据库更改还是处理 IoT 数据流,甚或是管理消息队列,每个应用程序都需要一种在执行这些操作时运行某些代码的方式。Whether you're building a web API, responding to database changes, processing IoT data streams, or even managing message queues - every application needs a way to run some code as these events occur.

为了满足此需求,Azure Functions 通过两种重要方式提供了“按需计算”。To meet this need, Azure Functions provides "compute on-demand" in two significant ways.

首先,通过 Azure Functions 可将系统的逻辑实现为可直接使用的代码块。First, Azure Functions allows you to implement your system's logic into readily available blocks of code. 这些代码块称为“函数”。These code blocks are called "functions". 当需要对关键事件作出响应时,可以随时运行不同的函数。Different functions can run anytime you need to respond to critical events.

其次,当请求增加时,Azure Functions 可以根据需要(但仅在需要时)提供尽可能多的资源和函数实例以满足需求。Second, as requests increase, Azure Functions meets the demand with as many resources and function instances as necessary - but only while needed. 当请求减少时,所有额外的资源和应用程序实例都会自动减少。As requests fall, any extra resources and application instances drop off automatically.

所有的计算资源来自何处?Where do all the compute resources come from? Azure Functions 根据需要提供任意数量的计算资源以满足应用程序的需求。Azure Functions provides as many or as few compute resources as needed to meet your application's demand.

按需提供计算资源是 Azure Functions 中无服务器计算最根本的特性。Providing compute resources on-demand is the essence of serverless computing in Azure Functions.

方案Scenarios

在许多情况下,函数与一系列云服务相集成,可提供功能丰富的实现。In many cases, a function integrates with an array of cloud services to provide feature-rich implementations.

以下是一组常见 但并非详尽的 Azure Functions 方案集。The following are a common, but by no means exhaustive, set of scenarios for Azure Functions.

若希望...If you want to... 然后...then...
生成 Web APIBuild a web API 使用 HTTP 触发器为 Web 应用程序实现终结点Implement an endpoint for your web applications using the HTTP trigger
处理文件上传Process file uploads blob 存储中上传或更改文件时运行代码Run code when a file is uploaded or changed in blob storage
构建无服务器工作流Build a serverless workflow 使用持久函数将一系列函数链接在一起Chain a series of functions together using durable functions
响应数据库更改Respond to database changes Cosmos DB 中创建或更新文档时运行自定义逻辑Run custom logic when a document is created or updated in Cosmos DB
运行计划任务Run scheduled tasks 设定的时间执行代码Execute code at set times
创建可靠消息队列系统Create reliable message queue systems 使用队列存储服务总线事件中心来处理消息队列Process message queues using Queue Storage, Service Bus, or Event Hubs
分析 IoT 数据流Analyze IoT data streams 收集并处理来自 IoT 设备的数据Collect and process data from IoT devices
实时处理数据Process data in real time 使用 Functions 和 SignalR 即时响应数据Use Functions and SignalR to respond to data in the moment

生成函数时,可以使用以下选项和资源:As you build your functions, you have the following options and resources available:

后续步骤Next Steps