我需要在重试之间实现一些延迟,理想情况下是通过队列上消息的可见性延迟。异常后的 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"
}
}
}
}
[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/