Azure WebJobs:VisibilityTimeout 和 MaxDequeuCount 不能一起工作

Azure WebJobs: VisibilityTimeout & MaxDequeuCount does not work together

我正在使用 Azure WebJobs SDK 2.0,当我指定 VisibilityTimeout 然后指定 MaxDequeuCount 时,消息在失败 3 次时不会从队列中删除,而只会复制到毒队列。可以看到DequeueCount大于MaxDequeuCount,消息还在队列中。

class Program
    {
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var config = new JobHostConfiguration();

            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            config.Queues.BatchSize = 8;
            config.Queues.MaxDequeueCount = 3;
            config.Queues.VisibilityTimeout = TimeSpan.FromSeconds(5);
            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(3);


            var host = new JobHost(config);
            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
    }

该函数正在抛出异常以模拟错误情况。

 public class Functions
    {
        // This function will get triggered/executed when a new message is written 
        // on an Azure Queue called queue.
        public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
        {
            log.WriteLine(message);
            throw new Exception("There was an error processing the message");
        }
    }

经过 3 次尝试后,邮件被移至毒物队列,这是预期的,但在 10 分钟左右后,被移至毒物队列的邮件再次出现在队列中。 console output

在队列中您可以看到 Dequeue 计数大于 MaxDequeuCount,但消息仍未从队列中删除。queue

在病毒队列中,您可以看到 M1 消息被处理了两次。

message is not removed from the queue when it fails 3 times but only copied to poison queue

据我所知,目前我们无法将 Storage SDK 8.x 与 WebJobs SDK 一起使用,其他人也报告了类似的问题。

如果您使用的是Azure Storage SDK8.x,请尝试降级Azure Storage SDK的版本。此外,在第二个link中,asiffermann 与我们分享了一个变通示例:编写自定义 QueueProcessor 以在 CopyMessageToPoisonQueueAsync 中创建一个新的 CloudQueueMessage,请参考。