Search code examples
c#azure-servicebus-queues

Set WaitTimeOut for Azure Service Bus Session Processor


In the legacy version of Azure Service Bus (ASB) I can use MessageWaitTimeout in SessionHandlerOptions to control the timeout between 2 messages. For example, if I set timeout 5 seconds, after complete the first message, the queue waits for 5s then picks the next message.

In the new version Azure.Messaging.ServiceBus, the queue has to wait for around 1 minute to pick up the next message. I only need to process one-by-one messages, no need to process concurrent messages.

I follow this example and can't find any solution to set timeout like the old version. Does anyone know how to do it?

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

EDIT: I found the solution. It is RetryOptions in ServiceBusClient

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

Solution

  • With the latest stable release, 7.2.0, this can be configured with the SessionIdleTimeout property.