Azure Functions 2.x 的 host.json 参考host.json reference for Azure Functions 2.x

host.json 元数据文件包含对函数应用的所有函数产生影响的全局配置选项。The host.json metadata file contains global configuration options that affect all functions for a function app. 本文列出了可用于 v2 运行时的设置。This article lists the settings that are available for the v2 runtime.

Note

本文适用于 Azure Functions 2.x。This article is for Azure Functions 2.x. 有关 Functions 1.x 中 host.json 的参考,请参阅 Azure Functions 1.x 的 host.json 参考For a reference of host.json in Functions 1.x, see host.json reference for Azure Functions 1.x.

其他函数应用配置选项在应用设置中进行管理。Other function app configuration options are managed in your app settings.

local.settings.json 文件中的某些 host.json 设置仅在本地运行时才使用。Some host.json settings are only used when running locally in the local.settings.json file.

示例 host.json 文件Sample host.json file

以下示例 host.json 文件指定了所有可能的选项。The following sample host.json files have all possible options specified.

{
    "version": "2.0",
    "extensions": {
        "cosmosDb": {},
        "durableTask": {},
        "eventHubs": {},
        "http": {},
        "queues": {},
        "sendGrid": {},
        "serviceBus": {}
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    },
    "functions": [ "QueueProcessor", "GitHubWebHook" ],
    "functionTimeout": "00:05:00",
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    },
    "managedDependency": {
        "enabled": true
    },
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    },
    "watchDirectories": [ "Shared", "Test" ]
}

本文的以下各部分解释了每个顶级属性。The following sections of this article explain each top-level property. 除非另有说明,否则其中的所有属性都是可选的。All are optional unless otherwise indicated.

CosmosDBcosmosDb

可在 Cosmos DB 触发器和绑定中查找配置设置。Configuration setting can be found in Cosmos DB triggers and bindings.

durableTaskdurableTask

可在 Durable Functions 的绑定中查找配置设置。Configuration setting can be found in bindings for Durable Functions.

eventHubeventHub

可在事件中心触发器和绑定中查找配置设置。Configuration settings can be found in Event Hub triggers and bindings.

扩展extensions

返回包含所有特定于绑定的设置的对象的属性,例如 httpeventHubProperty that returns an object that contains all of the binding-specific settings, such as http and eventHub.

extensionBundleextensionBundle

扩展捆绑可让你将一组兼容的 Functions 绑定扩展添加到函数应用。Extension bundles lets you add a compatible set of Functions binding extensions to your function app. 若要了解详细信息,请参阅用于本地开发的扩展捆绑To learn more, see Extension bundles for local development.

{
    "version": "2.0",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}

以下属性可在 extensionBundle 中使用:The following properties are available in extensionBundle:

属性Property DescriptionDescription
idid Azure Functions 扩展捆绑的命名空间。The namespace for Azure Functions extension bundles.
版本version 要安装的捆绑的版本。The version of the bundle to install. Functions 运行时始终选取按版本范围或间隔定义的最宽松版本。The Functions runtime always picks the maximum permissible version defined by the version range or interval. 上述版本值允许使用从 1.0.0 到 2.0.0(不含 2.0.0)的所有捆绑版本。The version value above allows all bundle versions from 1.0.0 up to but not including 2.0.0. 有关详细信息,请参阅用于指定版本范围的间隔表示法For more information, see the interval notation for specifying version ranges.

捆绑中的包发生变化时,捆绑版本将会递增。Bundle versions increment as packages in the bundle change. 当捆绑中的包增加主版本时,就会发生主版本更改。Major version changes occur when packages in the bundle increment by a major version. 捆绑中的主版本更改通常与 Functions 运行时的主版本更改一致。Major version changes in the bundle usually coincide with a change in the major version of the Functions runtime.

默认捆绑安装的当前扩展集将在此 extensions.json 文件中枚举。The current set of extensions installed by the default bundle is enumerated in this extensions.json file.

functionsfunctions

作业主机运行的函数列表。A list of functions that the job host runs. 空数组表示运行所有函数。An empty array means run all functions. 仅供在本地运行时使用。Intended for use only when running locally. 在 Azure 的函数应用中,应改为按照如何在 Azure Functions 中禁用函数中的步骤禁用特定函数,而不是使用此设置。In function apps in Azure, you should instead follow the steps in How to disable functions in Azure Functions to disable specific functions rather than using this setting.

{
    "functions": [ "QueueProcessor", "GitHubWebHook" ]
}

functionTimeoutfunctionTimeout

指示所有函数的超时持续时间。Indicates the timeout duration for all functions. 它采用 timespan 字符串格式。It follows the timespan string format. 在无服务器消耗计划中,有效范围为 1 秒至 10 分钟,默认值为 5 分钟。In a serverless Consumption plan, the valid range is from 1 second to 10 minutes, and the default value is 5 minutes.
在专用(应用服务)计划中,没有总体限制,默认值为 30 分钟。In a Dedicated (App Service) plan, there is no overall limit, and the default value is 30 minutes. -1 表示无限执行。A value of -1 indicates unbounded execution.

{
    "functionTimeout": "00:05:00"
}

healthMonitorhealthMonitor

主机运行状况监视器的配置设置。Configuration settings for Host health monitor.

{
    "healthMonitor": {
        "enabled": true,
        "healthCheckInterval": "00:00:10",
        "healthCheckWindow": "00:02:00",
        "healthCheckThreshold": 6,
        "counterThreshold": 0.80
    }
}
属性Property 默认Default 说明Description
enabledenabled true 指定是否已启用该功能。Specifies whether the feature is enabled.
healthCheckIntervalhealthCheckInterval 10 秒10 seconds 定期后台运行状况检查之间的时间间隔。The time interval between the periodic background health checks.
healthCheckWindowhealthCheckWindow 2 分钟2 minutes healthCheckThreshold 设置结合使用的滑动时间窗口。A sliding time window used in conjunction with the healthCheckThreshold setting.
healthCheckThresholdhealthCheckThreshold 66 在启动主机回收之前,运行状况检查可以失败的最大次数。Maximum number of times the health check can fail before a host recycle is initiated.
counterThresholdcounterThreshold 0.800.80 性能计数器将被视为不正常的阈值。The threshold at which a performance counter will be considered unhealthy.

httphttp

可在 http 触发器和绑定中查找配置设置。Configuration settings can be found in http triggers and bindings.

managedDependencymanagedDependency

托管依赖项是一项功能,目前仅支持基于 PowerShell 的函数。Managed dependency is a feature that is currently only supported with PowerShell based functions. 它使依赖项可以由服务自动管理。It enables dependencies to be automatically managed by the service. enabled 属性设置为 true 时,requirements.psd1 文件会被处理。When the enabled property is set to true, the requirements.psd1 file is processed. 发布任何次要版本时会更新依赖项。Dependencies are updated when any minor versions are released.

{
    "managedDependency": {
        "enabled": true
    }
}

queuesqueues

可在存储队列触发器和绑定中查找设置。Configuration settings can be found in Storage queue triggers and bindings.

SendGridsendGrid

可在 SendGrid 触发器和绑定中查找配置设置。Configuration setting can be found in SendGrid triggers and bindings.

serviceBusserviceBus

可在服务总线触发器和绑定中查找配置设置。Configuration setting can be found in Service Bus triggers and bindings.

singletonsingleton

单一实例锁行为的配置设置。Configuration settings for Singleton lock behavior. 有关详细信息,请参阅有关单一实例支持的 GitHub 问题For more information, see GitHub issue about singleton support.

{
    "singleton": {
      "lockPeriod": "00:00:15",
      "listenerLockPeriod": "00:01:00",
      "listenerLockRecoveryPollingInterval": "00:01:00",
      "lockAcquisitionTimeout": "00:01:00",
      "lockAcquisitionPollingInterval": "00:00:03"
    }
}
属性Property 默认Default 说明Description
lockPeriodlockPeriod 00:00:1500:00:15 占用函数级锁的时间段。The period that function level locks are taken for. 锁自动续订。The locks auto-renew.
listenerLockPeriodlistenerLockPeriod 00:01:0000:01:00 占用侦听器锁的时间段。The period that listener locks are taken for.
listenerLockRecoveryPollingIntervallistenerLockRecoveryPollingInterval 00:01:0000:01:00 在启动时无法获取侦听器锁的情况下,用于恢复侦听器锁的时间间隔。The time interval used for listener lock recovery if a listener lock couldn't be acquired on startup.
lockAcquisitionTimeoutlockAcquisitionTimeout 00:01:0000:01:00 运行时尝试获取锁的最长时间。The maximum amount of time the runtime will try to acquire a lock.
lockAcquisitionPollingIntervallockAcquisitionPollingInterval 不适用n/a 尝试获取锁的间隔时间。The interval between lock acquisition attempts.

版本version

针对 v2 运行时的函数应用需要版本字符串 "version": "2.0"The version string "version": "2.0" is required for a function app that targets the v2 runtime.

watchDirectorieswatchDirectories

应该监视其更改情况的一组共享代码目录A set of shared code directories that should be monitored for changes. 确保当这些目录中的代码发生更改时,函数会拾取这些更改。Ensures that when code in these directories is changed, the changes are picked up by your functions.

{
    "watchDirectories": [ "Shared" ]
}

后续步骤Next steps