将 BrokeredMessage 移动到 Azure Function v1 中的死信后出现 MessageLockLostException

MessageLockLostException after moving BrokeredMessage to dead letter in Azure Function v1

我有一个通过服务总线主题触发的 Azure Function v1。如果发生任何错误,我将 BrokeredMessage 放入死信。它似乎有效,但之后我在函数的日志流中看到以下内容:

2019-11-19T10:49:31.382 [Error] MessageReceiver error (Action=Complete) : Microsoft.ServiceBus.Messaging.MessageLockLostException: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.

以下是我将 BrokeredMessage 放入死信的方式:

myBrokeredMessage.DeadLetter(deadLetterReason, exception.Message);
// after this I have tried following but doesn't work:
// 1. do nothing
// 2. myBrokeredMessage.Complete();
// 3. myBrokeredMessage.Abandon();

我的功能运行没问题。但是在它有 运行 并执行上面的代码之后,该错误似乎出现在日志流中。它似乎在做我想做的事(将 BrokeredMessage 放入死信队列),但该错误似乎不太好,我想修复它。我想我没有正确处理某种锁。

我应该怎么做才能修复该错误?

What should I do to fix that error?

这与其说是错误,不如说是警告。 Functions 的设计方式是默认情况下函数完成或死信消息。如果您控制传入消息发生的情况,Functions 运行时不会这样做,并且仍然尝试应用完成逻辑,因为从它的角度来看,用户代码没有抛出异常,因此应该认为传入消息已成功处理并完成。

Functions 2.x 有一个主机设置,您可以将其打开以允许手动完成并禁用自动完成。这在 v1.0 中不可用,因此您必须忽略记录的错误。或者,升级到 2.x.