延迟天蓝色功能V2中的消息:提供的锁无效 [英] Defer message in azure function V2: The lock supplied is invalid

查看:106
本文介绍了延迟天蓝色功能V2中的消息:提供的锁无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的azure函数中,有时我想推迟我的消息.但是,如果这样做,我会得到一个例外:

In my azure function, at some point I would like to defer my message. But if I do, I get an exception:

[7/30/2020 5:59:02 PM] Message processing error (Action=Complete, ClientId=MessageReceiver1UserCreated/Subscriptions/MySubscription, EntityPath=UserCreated/Subscriptions/MySubscription, Endpoint=xxxxxxxxxxx.servicebus.windows.net)
[7/30/2020 5:59:02 PM] Microsoft.Azure.ServiceBus: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance.

这是我的代码

[FunctionName("UserCreated")]
public static async Task Run([ServiceBusTrigger("UserCreated", "MySubscription", Connection = "ServiceBusConnectionString")]UserCreated userCreated, ILogger log, string lockToken, MessageReceiver messageReceiver)
{
    //some logic.....

    await messageReceiver.DeferAsync(lockToken);
}

老实说,我不知道自己在做什么错.找到的代码示例ID以及此 StackOverflow:Azure Function V2服务总线消息延迟 a>发布,对我没有帮助.

Honestly I have no clue what I am doing wrong. Code examples id found and also this StackOverflow: Azure Function V2 Service Bus Message Deferral post, does not help me out.

我了解该消息会在功能完成后自动完成.因此,我尝试禁用自动完成功能,但在那里我仍未找到有效的解决方案.

I understand that the message is automatically completed after the function completes. So I tried to disable autocomplete but also there I did not succeed to find a working solution.

使用软件包:

  • Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.1.0
    • (引用)Microsoft.Azure.ServiceBus 4.1.1
    • Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.1.0
      • (references) Microsoft.Azure.ServiceBus 4.1.1

      推荐答案

      感谢所有答案,但没有人能真正解释真正的原因.

      Thanks for all answers however none actually explained the real cause.

      如果您想自己完成,推迟,放弃或删除邮件,则必须在host.json文件中禁用自动完成.

      If you want to complete, defer, abandon or remove the message yourself, you have to disable autocomplete in the host.json file.

      锁定无效的原因是:

      提供的锁无效. 锁已过期,或者消息已从队列中删除 ,或者已由其他接收者实例接收.

      The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue, or was received by a different receiver instance.

      在我的情况下,该邮件已被删除",因为我使用messageReceiver.DeferAsync(lockToken);

      In my case the message was already "removed" since I used messageReceiver.DeferAsync(lockToken);

      因此,这意味着在执行此语句之后,该函数会自动完成消息(已延迟).

      So this means that after this statement, the function automatically completes the message (which is already deferred).

      因此,您必须禁用邮件的自动完成.

      Therefore you have to disable autocompletion of the message.

      host.json

      "extensions": {
        "serviceBus": {
          "messageHandlerOptions": {
            "autoComplete": false
          }
        }
      }
      

      小心

      在禁用自动完成功能时,您有责任对消息进行处理.您始终必须做出决定,否则锁定超时后,该消息将再次变为可用.

      Be careful

      When disabling autocomplete, you are responsible to do something with the message. You always have to make a decision otherwise the message will become available again after lock timeout.

      这篇关于延迟天蓝色功能V2中的消息:提供的锁无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆