c# - Azure 函数 V2 中的延迟消息 : The lock supplied is invalid

标签 c# azure azure-functions azureservicebus

在我的 azure 函数中,有时我想推迟我的消息。但如果我这样做,我会得到一个异常(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 Service Bus Message Deferral帖子,对我没有帮助。

据我了解,该消息是在函数完成后自动完成的。因此,我尝试禁用自动完成功能,但也没有成功找到可行的解决方案。

使用包:

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

最佳答案

正如错误消息所述,消息可能在到达 Defer 指令之前失去锁定。尝试延长服务总线上的锁定超时。我认为这可能会解决这个问题。

关于c# - Azure 函数 V2 中的延迟消息 : The lock supplied is invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63179056/

相关文章:

c# - ASP.NET Core Web API - 执行 'LastOrDefault' 操作的查询必须具有确定性排序顺序

git - 多个项目的 Azure 持续部署

spring-boot - 访问KeyVault时出现SslHandshakeTimeoutException(SpringBoot 2.7)

将数据传输到 Azure SQL 数据库的 Azure 体系结构问题

C# ListView 显示

c# - 其他语言的 PEAR 替代品

c# - 如何在 C# Azure 函数中将多个参数作为数组传递?

azure - Azure Durable Functions 是否支持 .NET 6 和 Azure Functions 版本 4?

c# - 将 app.xaml 样式拆分为文件

azure - 以编程方式验证是否在 Cosmos DB 集合上启用了 TTL