Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebJobs Not Retrying Failed Queue Message

I have the following logic in a WebJob using the new 0.3.0-beta WebJobs SDK. When my code fails processing the message, the Azure dashboard shows an Aggregate Exception (which makes sense since this is async). HOWEVER, it does not retry processing the message.

The very little documentation I've been able to find indicates that the message should be retried within 10 minutes of failure. Is this not the case with the new 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);
}

The exception I get stems from a SQL Timeout exception (its a db query against SQL Azure in my code):

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
like image 809
ericb Avatar asked Jun 27 '14 12:06

ericb


1 Answers

You should set MaxDequeueCount.

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

That will retry 10 times, before the messages is put on a dead/bad letter queue.

You could also use a custom retry policy in the function. I suggest you look at "The Transient Fault Handling Application Block" https://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50).aspx

Or you could enable retry in EF with a SqlAzureExecutionStrategy https://msdn.microsoft.com/en-us/data/dn456835.aspx

like image 86
henrikwh Avatar answered Oct 31 '22 13:10

henrikwh