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 2.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. 与业务流程协调程序函数不同,实体函数没有任何特定的代码约束。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 2.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

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

更新代码Update your code

Durable Functions 2.0 引入了几项中断性变更。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 Functions 升级到 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.

默认的任务中心名称更改Default taskhub name changes

在版本 1.x 中,如果未在 host.json 中指定任务中心名称,则该名称默认为“DurableFunctionsHub”。In version 1.x, if a task hub name was not specified in host.json, it was defaulted to "DurableFunctionsHub". 在版本 2.x 中,默认的任务中心名称现在派生自函数应用的名称。In version 2.x, the default task hub name is now derived from the name of the function app. 因此,如果在升级到 2.x 时未指定任务中心名称,则代码会使用新的任务中心进行操作,并且所有正在进行的业务流程将不再有处理它们的应用程序。Because of this, if you have not specified a task hub name when upgrading to 2.x, your code will be operating with new task hub, and all in-flight orchestrations will no longer have an application processing them. 若要解决此情况,可以显式将任务中心名称设置为 v1.x 默认值“DurableFunctionsHub”,也可以参阅我们的零停机部署指南,详细了解如何处理正在进行的业务流程的中断性变更。To work around this, you can either explicitly set your task hub name to the v1.x default of "DurableFunctionsHub", or you can follow our zero-downtime deployment guidance for details on how to handle breaking changes for in-flight orchestrations.

公共接口更改(仅 .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.

function.json 更改(JavaScript 和 C# Script)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.