简体   繁体   English

Azure ServiceBusProcessor 需要很长时间才能停止

[英]Azure ServiceBusProcessor takes a long time to stop

I'm playing around with sending messages through the Azure Service Bus library Azure.Messaging.ServiceBus.我正在玩通过 Azure 服务总线库 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).调用 processor.StopProcessingAsync() 时,该操作大约需要一分钟(每次)。 When looking in the Azure portal, all messaged processed.在 Azure 门户中查看时,所有消息都已处理。 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.在浏览源代码时,我发现接收器启动后有一个默认的“等待时间”,即 60 秒。 This can be lowered by setting TryTimeout on ServiceBusClientOptions.ServiceBusRetryOptions.这可以通过在 ServiceBusClientOptions.ServiceBusRetryOptions 上设置TryTimeout来降低。

See: ServiceBusRetryOptions AmqpReceiver.ReceiveMessagesAsyncInternal请参阅: 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.将超时设置为 5 秒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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