Azure 服务总线队列接收器是否有超时限制?

Do Azure Service Bus Queues Receivers have a Timeout Limit?

我们正在收到来自 Azure 服务总线队列的消息。队列上的接收者(消息处理程序)调用应用程序服务,更新 SQL 数据库 table 中的百万条以上记录,处理时间超过 30 分钟。

Azure 服务总线队列是否有超时限制?这会导致 SQL Table 进程停止更新行吗?

https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues

正在发送的实际服务总线消息队列非常小,只有 YearProductType。然后应用服务方法将接受这两个参数,并更新整个 sql table.

Azure 服务总线队列方法 ---> 服务总线消息接收(事件处理程序)---> 调用应用服务更新 SQL Table

简短回答:在 Peek-Lock 接收模式下,支持的最长锁定持续时间为 5 分钟

现在是长答案:)

有 2 个 modes 服务总线消息接收器。

  1. Peek-Lock模式(non-destructive):如果在创建QueueClient时没有指定,这是默认的(constructor has overload which accepts ReceiveMode). In this mode, receive locks/hides the message for the client for a period (called lock duration) which is a setting of the queue (you can check in Azure portal). Max supported value is 5 minutes. If your processing is not complete by then and you do not complete the message (CompleteAsync), the lock expires and the message reappears in the queue. For more details, refer https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock

对于long-running 操作,一种技术是renew the lock 间隔小于锁定持续时间。在您所关注的示例中,您可以在 MessageHandlerOptions 中设置 MaxAutoRenewDuration 属性,它可以自动为您续订。

另一种技术可以利用 Message deferral 功能,您在接收时开始处理,但继续推迟消息检索,直到您的过程完成,此时您收到消息并完成。有点复杂,但很聪明。

  1. 接收和删除模式(破坏性):在这种模式下,顾名思义,消息在接收时从队列中删除。所以你可以花尽可能长的时间来处理。但问题是如果您的客户端在处理过程中崩溃,您将面临永远丢失消息的风险。