azure-functions - 如何获取 Azure 服务总线触发的 Azure Function V3 背后的底层 MessageReceiver 引用

标签 azure-functions azureservicebus

我已将 Azure Function 配置为在触发 Azure Function 时不显示“自动完成”消息。我的问题是我需要自己将消息标记为完整,并在事务的上下文中执行此操作(如下)。使用“via”路由的此事务在控制台应用程序中有效,但在 Azure 中失败,因为缺少对使消息出队的原始接收者的引用。

如何获取底层接收者引用,以便我可以原子地完成和发送?在 Azure Functions 中似乎无法执行此操作。

using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
      try
      {
         await receiver.CompleteAsync(completeMessage.SystemProperties.LockToken);

         for (var i = 0; i <= sendMessages.Length - 1; i++)
            await sender.SendAsync(sendMessages[i]);

         ts.Complete();
      }
      catch (Exception ex)
      {
         // This rolls back send and complete in case an exception happens
      }
}

如果没有原始接收者引用(以及您自己新创建的引用),您会得到以下异常:

ERROR: Microsoft.Azure.ServiceBus.MessageLockLostException: 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.

最佳答案

您需要注入(inject)函数使用的消息接收器来接收传入消息。注入(inject)是通过函数参数完成的。 This post进入细节。

关于azure-functions - 如何获取 Azure 服务总线触发的 Azure Function V3 背后的底层 MessageReceiver 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63185046/

相关文章:

c# - 如何在 ServiceBusTrigger azure 函数中进行持久的后调用?

azure - 使用 Azure Powershell 函数从 Azure Blob 存储读取 XLSX 文件

azure - 如何在 Azure 服务总线诊断日志上记录订阅自动删除事件?

Azure 推送通知随机工作

SignalR 服务总线主题名称冲突

c# - 无法从 Visual Studio 2017 调试和发布 Azure Function

.net - 从 Azure Web API 使用 Azure Analysis Services 数据

使用应用程序设置 json 的 Azure Function 2.0

azure - 服务总线主题 : Subscription Filter Rules not working when sending a message via Logic App Connector

azure - 使用 Azure 服务总线向客户端发送消息 - 主题