Azure 存储 queue/functions,仅从毒队列中出列一次

Azure storage queue/functions, dequeue from poison queue only once

我对 azure 存储函数+azure 存储队列有疑问。 我有一个队列 - "myQueue" 和队列触发的 azure 函数 "func1"。在 host.json 中,我配置了 maxDequeueCount(5) 和 visibilityTimeout - 一切正常。

5 次尝试后,我的消息转到 "myQueue-poison"。 我有第二个 azure 函数 "func2"(从 func1 复制粘贴),它是从 "myQueue-poison" 队列触发的。我还在 host.json 中为此函数设置了 maxDequeueCount 和 visibilityTimeout。但是这个函数只被触发一次——在第一次失败后 运行 我的消息从队列中消失了。 怎么了? host.json 和 c# 代码相同 - 只有队列的名称不同。

下面是函数 1 和函数 2 的代码。

[FunctionName("Function1")]
        public static void Run([QueueTrigger("myqueue-poison", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log)
        {
            Exception ex = new Exception();
            throw ex;
        }



 [FunctionName("Function2")]
        public static void Run([QueueTrigger("myqueue", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log)
        {
            Exception ex = new Exception();            
            throw ex;
        }

示例日志消息,其中从毒物队列处理消息时出现延迟。

 [12/5/2018 9:39:16 PM] Loading functions metadata
    [12/5/2018 9:39:16 PM] 2 functions loaded
    [12/5/2018 9:39:17 PM] Generating 2 job function(s)
    [12/5/2018 9:39:17 PM] Found the following functions:
    [12/5/2018 9:39:17 PM] FunctionApp1.Function1.Run
    [12/5/2018 9:39:17 PM] FunctionApp1.Function2.Run
    [12/5/2018 9:39:17 PM]
    [12/5/2018 9:39:17 PM] Host initialized (662ms)
    [12/5/2018 9:39:17 PM] Host started (707ms)
    [12/5/2018 9:39:17 PM] Job host started
    Hosting environment: Production
    Content root path: C:\Users\username\source\repos\FunctionApp1\FunctionApp1\bin\Debug\netstandard2.0
    Now listening on: http://0.0.0.0:7071
    Application started. Press Ctrl+C to shut down.
    [12/5/2018 9:39:18 PM] Executing 'Function2' (Reason='New queue message detected on 'myqueue'.', Id=20bf83c5-3142-4092-9d85-7a2a6fbcf863)
    [12/5/2018 9:39:18 PM] Executed 'Function2' (Failed, Id=20bf83c5-3142-4092-9d85-7a2a6fbcf863)
    [12/5/2018 9:39:18 PM] System.Private.CoreLib: Exception while executing function: Function2. FunctionApp1: Exception of type 'System.Exception' was thrown.
    [12/5/2018 9:39:18 PM] Executing 'Function2' (Reason='New queue message detected on 'myqueue'.', Id=49775db2-0c91-41cb-b472-a3aceee1bac3)
    [12/5/2018 9:39:19 PM] Executed 'Function2' (Failed, Id=49775db2-0c91-41cb-b472-a3aceee1bac3)
    [12/5/2018 9:39:19 PM] System.Private.CoreLib: Exception while executing function: Function2. FunctionApp1: Exception of type 'System.Exception' was thrown.
    [12/5/2018 9:39:19 PM] Executing 'Function2' (Reason='New queue message detected on 'myqueue'.', Id=0a1d103a-41a0-4630-a479-c72297a368b8)
    [12/5/2018 9:39:19 PM] Executed 'Function2' (Failed, Id=0a1d103a-41a0-4630-a479-c72297a368b8)
    [12/5/2018 9:39:19 PM] System.Private.CoreLib: Exception while executing function: Function2. FunctionApp1: Exception of type 'System.Exception' was thrown.
    [12/5/2018 9:39:19 PM] Executing 'Function2' (Reason='New queue message detected on 'myqueue'.', Id=6b79aad1-1eb6-4cfe-b39c-a7078f006968)
    [12/5/2018 9:39:20 PM] Executed 'Function2' (Failed, Id=6b79aad1-1eb6-4cfe-b39c-a7078f006968)
    [12/5/2018 9:39:20 PM] System.Private.CoreLib: Exception while executing function: Function2. FunctionApp1: Exception of type 'System.Exception' was thrown.
    [12/5/2018 9:39:20 PM] Executing 'Function2' (Reason='New queue message detected on 'myqueue'.', Id=cf401aee-133d-42ac-a8e0-25fe95ebe162)
    [12/5/2018 9:39:20 PM] Executed 'Function2' (Failed, Id=cf401aee-133d-42ac-a8e0-25fe95ebe162)
    [12/5/2018 9:39:20 PM] System.Private.CoreLib: Exception while executing function: Function2. FunctionApp1: Exception of type 'System.Exception' was thrown.
    [12/5/2018 9:39:20 PM] Message has reached MaxDequeueCount of 5. Moving message to queue 'myqueue-poison'.
    [12/5/2018 9:39:20 PM] Executing 'Function1' (Reason='New queue message detected on 'myqueue-poison'.', Id=2b1bd5ec-67e2-41c9-bd7b-6a3fde48cd04)
    [12/5/2018 9:39:21 PM] Executed 'Function1' (Failed, Id=2b1bd5ec-67e2-41c9-bd7b-6a3fde48cd04)
    [12/5/2018 9:39:21 PM] System.Private.CoreLib: Exception while executing function: Function1. FunctionApp1: Exception of type 'System.Exception' was thrown.
    [12/5/2018 9:39:22 PM] Host lock lease acquired by instance ID '0000000000000000000000004EE22C73'.
[12/5/2018 9:49:20 PM] Executing 'Function1' (Reason='New queue message detected on 'myqueue-poison'.', Id=83f83d31-44e6-46cf-a235-08360e5adc60)
[12/5/2018 9:49:21 PM] Executed 'Function1' (Failed, Id=83f83d31-44e6-46cf-a235-08360e5adc60)
[12/5/2018 9:49:21 PM] System.Private.CoreLib: Exception while executing function: Function1. FunctionApp1: Exception of type 'System.Exception' was thrown.
[12/5/2018 9:59:21 PM] Executing 'Function1' (Reason='New queue message detected on 'myqueue-poison'.', Id=54acbb91-d4db-4737-ae90-47b17df5998c)
[12/5/2018 9:59:21 PM] Executed 'Function1' (Failed, Id=54acbb91-d4db-4737-ae90-47b17df5998c)
[12/5/2018 9:59:21 PM] System.Private.CoreLib: Exception while executing function: Function1. FunctionApp1: Exception of type 'System.Exception' was thrown.

所以看起来来自毒队列的消息的读取方式与普通队列不同。是否有任何配置可用于减少毒队列处理的延迟?

目前不支持此方案。

如果队列已经是毒队列,则不会为该毒队列创建后续毒队列。请参阅实施 here.

由于您的 poison-queue 没有第二个 poison queue,当您的 Function 仍在 运行 时,消息将不会被释放,也就是说,您可能需要 10 分钟才能再次看到该消息。请参阅实施 here.