![](/img/trans.png)
[英]How Azure Service Bus Queue delivers messages to client on HTTPs mode
[英]How to use a CancellationToken with the Azure Service Bus Queue client?
在Azure Service Bus队列客户端中,我使用ReceiveBatchAsync
方法等待指定的时间异步接收一批消息。
var messages = await queueClient.ReceiveBatchAsync(10, TimeSpan.FromSeconds(30));
我想彻底关闭我的应用程序,所以我在所有长时间运行的异步进程上实现了CancellationToken
,但似乎没有可取消的ReceiveBatchAsync
重载。
换句话说,我想这样做,但我不能:
var messages = await queueClient.ReceiveBatchAsync(10, TimeSpan.FromSeconds(30),
cancellationToken);
将CancellationToken
应用于此类不直接提供的任务的最佳方法是什么? 我不想在关机期间等待整整30秒。
你可能会像这样使用QueueClient.Abort
:
using (cancellationToken.Register(() => queueClient.Abort())
{
var messages = await queueClient.ReceiveBatchAsync(
10, TimeSpan.FromSeconds(30));
return messages; // or process it
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.