您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

Durable Functions 版本概述Durable Functions versions overview

Durable Functions 是 Azure FunctionsAzure WebJobs 的扩展,可用于在无服务器环境中编写有状态函数。Durable Functions is an extension of Azure Functions and Azure WebJobs that lets you write stateful functions in a serverless environment. 该扩展可用于管理状态、检查点和重启。The extension manages state, checkpoints, and restarts for you. 如果你尚不熟悉 Durable Functions,请参阅概述文档If you are not already familiar with Durable Functions, see the overview documentation.

2.x 中的新增功能New features in 2.x

本部分介绍了在版本2.x 中添加的 Durable Functions 的功能。This section describes the features of Durable Functions that are added in version 2.x.

持久性实体Durable entities

在 Durable Functions 1.x 中,我们引入了一个新的实体函数概念。In Durable Functions 2.x, we introduced a new entity functions concept.

实体函数定义读取和更新较小状态片段(称为“持久实体”)的操作。Entity functions define operations for reading and updating small pieces of state, known as durable entities. 与业务流程协调程序函数一样,实体函数是具有特殊触发器类型“实体触发器”的函数。Like orchestrator functions, entity functions are functions with a special trigger type, entity trigger. 与 orchestrator 函数不同,实体函数没有任何特定的代码约束。Unlike orchestrator functions, entity functions do not have any specific code constraints. 实体函数还会显式管理状态,而不是通过控制流隐式表示状态。Entity functions also manage state explicitly rather than implicitly representing state via control flow.

若要了解详细信息,请参阅持久实体一文。To learn more, see the durable entities article.

持久 HTTPDurable HTTP

在 Durable Functions 1.x 中,我们引入了新的持久 HTTP功能,使你能够:In Durable Functions 2.x, we introduced a new Durable HTTP feature that allows you to:

  • 直接从业务流程函数调用 HTTP Api (有一些记录的限制)。Call HTTP APIs directly from orchestration functions (with some documented limitations).
  • 实现自动客户端 HTTP 202 状态轮询。Implement automatic client-side HTTP 202 status polling.
  • Azure 托管标识的内置支持。Built-in support for Azure Managed Identities.

若要了解详细信息,请参阅HTTP 功能一文。To learn more, see the HTTP features article.

从1.x 迁移到2。xMigrate from 1.x to 2.x

本部分介绍如何将现有版本 1.x Durable Functions 迁移到版本2.x 以利用新功能。This section describes how to migrate your existing version 1.x Durable Functions to version 2.x to take advantage of the new features.

升级扩展Upgrade the extension

在项目中安装Durable Functions 绑定扩展的版本2.x。Install version 2.x of the Durable Functions bindings extension in your project. 有关详细信息,请参阅Register Azure Functions 绑定扩展See Register Azure Functions binding extensions for more information.

更新代码Update your code

Durable Functions 2.x 引入了几项重大更改。Durable Functions 2.x introduces several breaking changes. Durable Functions 1.x 应用程序与不进行代码更改的 Durable Functions 2.x 不兼容。Durable Functions 1.x applications are not compatible with Durable Functions 2.x without code changes. 本部分列出了将版本1.x 函数升级到2.x 时必须做出的一些更改。This section lists some of the changes you must make when upgrading your version 1.x functions to 2.x.

Host json 架构Host.json schema

Durable Functions 2.x 使用新的 host json 架构。Durable Functions 2.x uses a new host.json schema. 1. x 的主要变化包括:The main changes from 1.x include:

  • 用于存储特定配置的 "storageProvider" (和 "azureStorage" 子节)。"storageProvider" (and the "azureStorage" subsection) for storage-specific configuration.
  • "tracing" 跟踪和日志记录配置。"tracing" for tracing and logging configuration.
  • 事件网格通知配置的 "notifications" (和 "eventGrid" 子节)。"notifications" (and the "eventGrid" subsection) for event grid notification configuration.

有关详细信息,请参阅Durable Functions host json 参考文档See the Durable Functions host.json reference documentation for details.

公共接口更改(仅适用于 .NET)Public interface changes (.NET only)

在版本1.x 中,Durable Functions 支持的各种_上下文_对象具有要在单元测试中使用的抽象基类。In version 1.x, the various context objects supported by Durable Functions have abstract base classes intended for use in unit testing. 作为 Durable Functions 2.x 的一部分,这些抽象基类被替换为接口。As part of Durable Functions 2.x, these abstract base classes are replaced with interfaces.

下表表示主要更改:The following table represents the main changes:

1.x1.x 2.x2.x
DurableOrchestrationClientBase IDurableOrchestrationClientIDurableClientIDurableOrchestrationClient or IDurableClient
DurableOrchestrationContextDurableOrchestrationContextBaseDurableOrchestrationContext or DurableOrchestrationContextBase IDurableOrchestrationContext
DurableActivityContextDurableActivityContextBaseDurableActivityContext or DurableActivityContextBase IDurableActivityContext
OrchestrationClientAttribute DurableClientAttribute

在抽象基类包含虚拟方法的情况下,这些虚方法已由 DurableContextExtensions中定义的扩展方法替换。In the case where an abstract base class contained virtual methods, these virtual methods have been replaced by extension methods defined in DurableContextExtensions.

函数 json 更改(JavaScript 和C#脚本)function.json changes (JavaScript and C# Script)

在 Durable Functions 1.x 中,业务流程客户端绑定使用 typeorchestrationClientIn Durable Functions 1.x, the orchestration client binding uses a type of orchestrationClient. 版本2.x 改用 durableClientVersion 2.x uses durableClient instead.