You need to enable JavaScript to run this app. Azure.Messaging.ServiceBus如何设置Session Processor消息等待超时
优惠活动
大模型
产品
解决方案
定价
更多

Azure.Messaging.ServiceBus如何设置Session Processor消息等待超时

Azure.Messaging.ServiceBus SDK 消息拉取间隔超时配置方案

问题背景

旧版Azure Service Bus (ASB) 中,可以通过SessionHandlerOptions的MessageWaitTimeout参数控制两条消息处理之间的等待超时时间。例如设置超时为5秒时,完成第一条消息处理后,队列会等待5秒再拉取下一条消息。
但在新版Azure.Messaging.ServiceBus SDK中,队列默认拉取下一条消息需要等待约1分钟,对于仅需逐条处理消息、无并发处理需求的业务场景,默认配置无法满足需求。
原有ServiceBusSessionProcessorOptions配置如下:

var options = new ServiceBusSessionProcessorOptions
{
    AutoCompleteMessages = false,
    MaxConcurrentSessions = 1,
    MaxConcurrentCallsPerSession = 1,
    MaxAutoLockRenewalDuration = TimeSpan.FromMinutes(2),
};

解决方案

实现与旧版MessageWaitTimeout功能等效的配置,需要调整ServiceBusClient的RetryOptions参数,将TryTimeout设置为预期的等待超时时长即可,配置示例如下:

var client = new ServiceBusClient("connectionString", new ServiceBusClientOptions
{
    RetryOptions = new ServiceBusRetryOptions
    {
        TryTimeout = TimeSpan.FromSeconds(5)
    }
});

内容的提问来源于stack exchange,提问作者Martinez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 11:06:03