简体   繁体   中英

Azure ServiceBusProcessor takes a long time to stop

I'm playing around with sending messages through the Azure Service Bus library Azure.Messaging.ServiceBus. I'm following this tutorial and sending/processing a single message.

When calling processor.StopProcessingAsync(), the action takes about a minute (each single time). When looking in the Azure portal, all messaged processed. I have no clue why it takes so long for the processor the stop even though there are no messages on the queue.

It seems like it takes the (exact) same amount of time each time. If anyone could point me to why it takes such a long time and how to reduce it (configuration/setup?), I would be more than thankful. Thanks in advance!

Ok. While going through the source code, I found that there's a default "wait time" after a receiver was started which is 60 seconds. This can be lowered by setting TryTimeout on ServiceBusClientOptions.ServiceBusRetryOptions.

See: ServiceBusRetryOptions AmqpReceiver.ReceiveMessagesAsyncInternal

I tested this, it works as expected:

var clientOptions = new ServiceBusClientOptions();
clientOptions.RetryOptions.TryTimeout = new TimeSpan(0, 0, 5);
await using var client = new ServiceBusClient(connectionString, clientOptions);

sets the timeout to 5 seconds.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM