【问题标题】:Azure storage queue/functions, dequeue from poison queue only onceAzure 存储队列/函数,仅从毒队列中出列一次
【发布时间】:2019-05-07 09:05:06
【问题描述】:

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

经过 5 次尝试后,我的消息转到“myQueue-poison”。 我有第二个天蓝色函数“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.

所以看起来毒队列中的消息与普通队列的读取方式不同。有没有什么配置可以用来减少毒队列处理的延迟?

【问题讨论】:

  • 您能否详细说明预期的行为、预期的原因以及代码在做什么?
  • 函数记录消息并抛出异常 - 我想测试重试。我希望 func1 运行 5 次,超时时间为 30 秒,func2 运行 15 次,超时时间为 5 分钟
  • @blidea 你的意思是,dequeue count 对毒队列不起作用?
  • @Baskar,是的,完全正确。
  • 是的,我验证了它创建了一个简单的样本,一旦从毒队列中出队,消息就会从毒队列中清除 - public static class Function1 { [FunctionName("Function1")] public static void Run ([QueueTrigger("myqueue-poison", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log) { Exception ex = new Exception(); log.LogInformation($"C# 队列触发函数处理:{myQueueItem}");扔前; } }

标签: azure azure-storage azure-functions azure-storage-queues


【解决方案1】:

目前不支持此方案。

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

由于您的毒物队列没有第二个毒物队列,当您的函数仍在运行时,该消息不会被释放,即您可能需要 10 分钟才能再次看到该消息。请参阅实现here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    • 2022-10-08
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2021-11-29
    相关资源
    最近更新 更多