c# - Azure函数通过clientRetryOptions和host.json进行队列绑定(bind)重试不起作用

标签 c# azure azure-functions azureservicebus

我正在按照 https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus?tabs=isolated-process%2Cextensionv5%2Cextensionv3&pivots=programming-language-csharp#hostjson-settings 使用隔离进程

我需要在重试之间实现一些延迟,理想情况下是通过队列上消息的可见性延迟。异常后的 Thread.Sleep 确实允许延迟,但会阻止其他消息的处理。

我宁愿避免持久功能

当通过 host.json 文件设置 clientRetryOptions 时(我认为应该适用于此),我没有看到任何效果,例如更少的最大重试次数或更大的延迟。

编辑:此设置仅用于连接到 Azure 服务总线吗?也许我需要与initialvisibilitydelay进行一些交互?

    {
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "clientRetryOptions": {
        "mode": "fixed",
        "tryTimeout": "00:03:00",
        "delay": "00:00:05.00",
        "maxDelay": "00:01:00",
        "maxRetries": 2
      }
    }
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

packages

        [Function("QueueTest")]
    public void Test([ServiceBusTrigger("test", Connection = "ServiceBusConnection")] string item,
     FunctionContext context)
    {
        StringBuilder log = new StringBuilder();
        log.AppendLine("Created at " + DateTime.Now);
        MessagingContext.ProcessedMessages.Add(new ProcessedMessage
        {
            Interface = "QueueTest",
            CreatedDate = DateTime.Now,
            Status = "Error",
            MessageId = "Test",
            QueueMessageId = "Test",
            Details = log.ToString()
        });
        MessagingContext.SaveChanges();
        throw new InvalidOperationException("Pretend failure");
    }

最佳答案

Azure Functions 不提供服务总线触发器的重试策略,而是依赖于 native 服务总线重试。 native 尝试使用服务总线不允许延迟重试。

有一个feature request支持以自定义延迟放弃消息,但尚未推出。另一种方法是接收消息、克隆消息,然后在完成原始消息的同时延迟发送消息,但这需要能够调用服务操作(完成消息、发送消息),而这目前也是不可能的。这是 tracking issue因为该功能正在 progerss 中工作。

关于c# - Azure函数通过clientRetryOptions和host.json进行队列绑定(bind)重试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76755635/

相关文章:

c# - 如何处理不支持绑定(bind)的图表?

c# - 从 DataTable 填充 ListView

WCF 服务空闲时间少于 5 分钟后响应缓慢(Azure 上的 4.0)

c# - 使用 ASP.NET MVC 应用程序定期插入 Azure 数据库

azure-functions - 多个 Azure Functions 核心工具版本

azure - 无法使用 Visual Studio Code 创建 Azure 逻辑应用工作流

c# - ToString 的默认数字格式

c# - 如何将 MSSQL 同步到 Elasticsearch?

azure - Windows 安装 Azure 文件共享并可以访问单个共享

Azure Functions - 消耗计划和冷启动