如何为单例配置 - 队列触发的 Azure 函数
How to configure for singleton - Queue Triggered Azure Function
我想要一个从 Azure 存储帐户队列触发到 运行 作为单例的 azure 函数。
函数应用程序在进程中并且 net6:
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
我的函数目前如下所示:
[FunctionName(nameof(QueueTrigger))]
[Singleton(Mode = SingletonMode.Listener)]
public async Task QueueBatch([QueueTrigger("TriggerSurvey")] TriggerMsg triggerMsg)
根据@Moho 的建议,我将以下内容添加到 host.json 和 Singleton 方法装饰器中,如上所示,但这对应用程序的行为没有影响。
"extensions": {
"queues": {
"maxPollingInterval": "00:00:02",
"visibilityTimeout": "00:00:30",
"batchSize": 1,
"maxDequeueCount": 5,
"newBatchThreshold": 8,
"messageEncoding": "base64"
}
}
我测试如下:
我向队列发布了一条消息。该函数使用它并开始工作 - 写入 Azure Sql。这项工作大约花费了 3 分钟,它在工作时多次插入日志 table,以及函数实例的相关 ID。在发布第一条消息几秒钟后,我发布了第二条消息。从日志中 table 我可以看到一个不同的函数实例已经消耗并且正在与第一个并发处理。
任何人都知道如何配置以便只有一个函数实例会轮询队列?
The batch size and the threshold for getting a new batch are
configurable in the host.json file. If you want to minimize parallel
execution for queue-triggered functions in a function app, you can set
the batch size to 1. This setting eliminates concurrency only so long
as your function app runs on a single virtual machine (VM).
host.json > extensions > queues > batchSize
我想要一个从 Azure 存储帐户队列触发到 运行 作为单例的 azure 函数。
函数应用程序在进程中并且 net6:
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
我的函数目前如下所示:
[FunctionName(nameof(QueueTrigger))]
[Singleton(Mode = SingletonMode.Listener)]
public async Task QueueBatch([QueueTrigger("TriggerSurvey")] TriggerMsg triggerMsg)
根据@Moho 的建议,我将以下内容添加到 host.json 和 Singleton 方法装饰器中,如上所示,但这对应用程序的行为没有影响。
"extensions": {
"queues": {
"maxPollingInterval": "00:00:02",
"visibilityTimeout": "00:00:30",
"batchSize": 1,
"maxDequeueCount": 5,
"newBatchThreshold": 8,
"messageEncoding": "base64"
}
}
我测试如下: 我向队列发布了一条消息。该函数使用它并开始工作 - 写入 Azure Sql。这项工作大约花费了 3 分钟,它在工作时多次插入日志 table,以及函数实例的相关 ID。在发布第一条消息几秒钟后,我发布了第二条消息。从日志中 table 我可以看到一个不同的函数实例已经消耗并且正在与第一个并发处理。
任何人都知道如何配置以便只有一个函数实例会轮询队列?
The batch size and the threshold for getting a new batch are configurable in the host.json file. If you want to minimize parallel execution for queue-triggered functions in a function app, you can set the batch size to 1. This setting eliminates concurrency only so long as your function app runs on a single virtual machine (VM).
host.json > extensions > queues > batchSize