【发布时间】:2020-01-28 09:16:32
【问题描述】:
有没有办法在运行时读取 host.json 文件中的主机设置? 假设你有一个这样的主机文件:
{
"version": "2.0",
"extensions": {
"serviceBus": {
"messageHandlerOptions": {
"maxConcurrentCalls": 16
}
}
}
}
然后如何从 C# 代码中读取 maxConcurrentCalls 设置?
最好也包含默认值。您应该在启动时获得与控制台中打印的相同的值:
[28-01-2020 09:16:06] LoggerFilterOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "MinLevel": "None",
[28-01-2020 09:16:06] "Rules": [
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "ProviderName": null,
[28-01-2020 09:16:06] "CategoryName": null,
[28-01-2020 09:16:06] "LogLevel": null,
[28-01-2020 09:16:06] "Filter": "<AddFilter>b__0"
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[28-01-2020 09:16:06] "CategoryName": null,
[28-01-2020 09:16:06] "LogLevel": "None",
[28-01-2020 09:16:06] "Filter": null
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "ProviderName": "Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.SystemLoggerProvider",
[28-01-2020 09:16:06] "CategoryName": null,
[28-01-2020 09:16:06] "LogLevel": null,
[28-01-2020 09:16:06] "Filter": "<AddFilter>b__0"
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] ]
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] FunctionResultAggregatorOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "BatchSize": 1000,
[28-01-2020 09:16:06] "FlushTimeout": "00:00:30",
[28-01-2020 09:16:06] "IsEnabled": true
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] SingletonOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "LockPeriod": "00:00:15",
[28-01-2020 09:16:06] "ListenerLockPeriod": "00:00:15",
[28-01-2020 09:16:06] "LockAcquisitionTimeout": "10675199.02:48:05.4775807",
[28-01-2020 09:16:06] "LockAcquisitionPollingInterval": "00:00:05",
[28-01-2020 09:16:06] "ListenerLockRecoveryPollingInterval": "00:01:00"
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] ServiceBusOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "PrefetchCount": 0,
[28-01-2020 09:16:06] "MessageHandlerOptions": {
[28-01-2020 09:16:06] "AutoComplete": true,
[28-01-2020 09:16:06] "MaxAutoRenewDuration": "00:05:00",
[28-01-2020 09:16:06] "MaxConcurrentCalls": 192
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] "SessionHandlerOptions": {
[28-01-2020 09:16:06] "AutoComplete": true,
[28-01-2020 09:16:06] "MaxAutoRenewDuration": "00:05:00",
[28-01-2020 09:16:06] "MaxConcurrentSessions": 2000,
[28-01-2020 09:16:06] "MessageWaitTimeout": "00:01:00"
[28-01-2020 09:16:06] },
[28-01-2020 09:16:06] "BatchOptions": {
[28-01-2020 09:16:06] "MaxMessageCount": 1000,
[28-01-2020 09:16:06] "OperationTimeout": "00:01:00",
[28-01-2020 09:16:06] "AutoComplete": true
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] }
[28-01-2020 09:16:06] HttpOptions
[28-01-2020 09:16:06] {
[28-01-2020 09:16:06] "DynamicThrottlesEnabled": false,
[28-01-2020 09:16:06] "MaxConcurrentRequests": -1,
[28-01-2020 09:16:06] "MaxOutstandingRequests": -1,
[28-01-2020 09:16:06] "RoutePrefix": "api"
[28-01-2020 09:16:06] }
【问题讨论】:
-
您可以从
local.settings.json使用它在运行时获取它 -
我特别想知道host.json的设置。这些不是我的设置,不应该存在于我的 local.settings.json 文件中。
-
旁注:可以在启动时看到设置(至少在本地),因为它们都打印在终端中。
-
@MikkelR.Lund 这是 host.json 的模板(函数 v2 或更高版本):docs.microsoft.com/en-us/azure/azure-functions/…
-
@BowmanZhu 是的,但这并没有告诉我运行时实际使用的是哪个设置。
标签: c# azure azure-functions settings