Azure Function Service Bus触发器触发的次数比队列中的消息触发的次数更多 [英] Azure Function Service Bus trigger fires more times than messages in the queue
本文介绍了Azure Function Service Bus触发器触发的次数比队列中的消息触发的次数更多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个服务总线队列和Azure服务总线队列触发器.
I have two Service Bus Queues and Azure Service Bus Queue Trigger.
该函数从队列中读取1000条消息并将其转发给另一个(用于测试)发布到Azure(计划使用量)时,即使队列中只有1000条消息,我也会得到1030+个功能命中.我认为这与功能实例的数量有关.
The function reads 1000 messages from the queue and forwards them to another (for test) When publishing to Azure (plan consumption) I get 1030+ function hits even though I only have 1000 messages in the queue. I think this has to do with the number of function instances.
问:如何为一个功能实例仅处理一次唯一消息?
Q: How to process 1 unique message only once for 1 function instance?
[FunctionName("Function1")]
public static async Task Run([ServiceBusTrigger("export-queue",
Connection = "Connection")]
string myQueueItem, ILogger log)
{
log.LogInformation($"Message: {myQueueItem}:{DateTime.Now}");
Thread.Sleep(2000);
queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
var message = new Message(Encoding.UTF8.GetBytes(myQueueItem));
await queueClient.SendAsync(message);
await queueClient.CloseAsync();
}
推荐答案
它对我有用.
为host.json添加扩展名:
Add extensions for your host.json :
"extensions": {
"serviceBus": {
"prefetchCount": 1,
"messageHandlerOptions": {
"autoComplete": true,
"maxConcurrentCalls": 1,
"maxAutoRenewDuration": "00:05:00"
},
"sessionHandlerOptions": {
"autoComplete": true,
"messageWaitTimeout": "00:00:30",
"maxAutoRenewDuration": "00:55:00",
"maxConcurrentSessions": 10
}
}
}
这篇关于Azure Function Service Bus触发器触发的次数比队列中的消息触发的次数更多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文