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.

问:如何对 1 个函数实例只处理 1 个唯一消息一次?

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆