6

我在使用新的 0.3.0-beta WebJobs SDK 的 WebJob 中有以下逻辑。当我的代码无法处理消息时,Azure 仪表板会显示一个聚合异常(这是有道理的,因为这是异步的)。但是,它不会重试处理该消息。

我能找到的极少文档表明该消息应在失败后 10 分钟内重试。新的SDK不是这样吗?

public static Task ProcessMyMessageAsync(
    [QueueTrigger(Config.MY_QUEUE)] string msg, 
    int dequeueCount, 
    CancellationToken cancellationToken)
{
    var processor = Config.Container.GetInstance<IMessageProcessor>();
    return processor.HandleJobAsync(msg, dequeueCount, cancellationToken);
}

我得到的异常源于 SQL Timeout 异常(它在我的代码中是针对 SQL Azure 的 db 查询):

System.AggregateException: System.AggregateException: One or more errors occurred. 
    ---> System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing  the command definition. See the inner exception for details. 
        ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. 
        ---> System.ComponentModel.Win32Exception: The wait operation timed out
4

1 回答 1

1

您应该设置 MaxDequeueCount。

JobHostConfiguration jobHostConf = new JobHostConfiguration();
jobHostConf.Queues.MaxDequeueCount = 10;
var host = new JobHost(jobHostConf);
host.RunAndBlock();

在将消息放入死信/坏信队列之前,这将重试 10 次。

您还可以在函数中使用自定义重试策略。我建议您查看“瞬态故障处理应用程序块” https://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx

或者您可以使用 SqlAzureExecutionStrategy 在 EF 中启用重试 https://msdn.microsoft.com/en-us/data/dn456835.aspx

于 2015-12-21T10:02:03.813 回答