简体   繁体   English

取消长期运行接收的Azure Service Bus QueueClient?

[英]Cancel an Azure Service Bus QueueClient long running Receive?

I am writing a test program to process messages in an Azure Service Bus Queue. 我正在编写一个测试程序来处理Azure Service Bus队列中的消息。 I want to be able to provide the the ability to start and stop the dequeueing functionality. 我希望能够提供启动和停止出队功能的能力。

If I am wondering if there is a way to cancel a call to QueueClient.Receive(TimeSpan)? 如果我想知道是否可以取消对QueueClient.Receive(TimeSpan)的调用? There is a QueueClient.Abort() method, and also a QueueClient.Close() method, but the documentation on these is sparse. 有一个QueueClient.Abort()方法,还有一个QueueClient.Close()方法,但是有关这些文档的文档很少。 And, there does not seem to be a corresponding method to "Open" after aborting or closing. 而且,中止或关闭后似乎没有相应的“打开”方法。

If there is no way to cancel a long running receive, then I am stuck using a short (or no) TimeSpan in order to get a chance for the user to stop dequeueing. 如果没有办法取消长时间运行的接收,那么我将使用较短的时间跨度(或没有时间跨度)而陷入困境,以便让用户有机会停止出队。 And by doing that I'm pretty much doing polling myself, which defeats the advantage of the long running receive functionality. 通过这样做,我几乎可以自己进行轮询了,这消除了长期运行的接收功能的优势。

I'm new to using the Service Bus Queue, so maybe I'm on the wrong track with my approach here, and not understanding the spirit of how messages in the queue are supposed to be processed? 我是使用Service Bus队列的新手,所以也许我在这里的方法走错了路,并且不了解应该如何处理队列中的消息的精神?

Close the message factory that created the queue client and the receiver will abort. 关闭创建队列客户端的消息工厂,接收方将中止。 Closing a messaging factory deletes the connection to the Service Bus service. 关闭消息传递工厂将删除与服务总线服务的连接。 Note that other MessagingEntities that have been created from the factory are also closed so use a dedicated factory for the receive loop. 请注意,还关闭了从工厂创建的其他MessagingEntities,因此请对接收循环使用专用工厂。

var myFactory = MessagingFactory.FromConnectionString(...);
myFactory.Close();

The Abort method on the QueueClient sometimes doesn't abort the actual receive operation within a reasonable time period in my experience. 根据我的经验,QueueClient上的Abort方法有时不会在合理的时间内中止实际的接收操作。

To start receiving again you will need to create a new QueueClient from a new MessagingFactory. 要再次开始接收,您将需要从新的MessagingFactory创建一个新的QueueClient。

Likely you will have this call on it's own background thread, to which you can simply kill the thread itself. 您可能会在自己的后台线程上进行此调用,您可以简单地杀死线程本身。 Side point, you should close the QueueClient object first. 侧面,您应该先关闭QueueClient对象。

When you are ready to receive again, create a new instance, and begin your background thread. 当您准备好再次接收时,请创建一个新实例,然后开始您的后台线程。

设计解决方案确实是为了关闭客户。

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

相关问题 Windows Azure服务总线队列 - MessageSender或QueueClient? - Windows Azure Service Bus Queues - MessageSender or QueueClient? Azure服务总线队列-当消息在队列中时,QueueClient.Receive()返回空的BrokeredMessage - Azure Service Bus Queue - QueueClient.Receive() returning null BrokeredMessage when messages are in the queue MessageLockLostException中断服务总线QueueClient - MessageLockLostException breaks Service Bus QueueClient 具有事务的长期运行作业 Azure 服务总线的模式 - Pattern for long running jobs Azure Service Bus with transactions 如何测试QueueClient是否可以成功连接到Azure服务总线队列? - How can I test if QueueClient can successfully connect to an Azure Service Bus Queue? 调用QueueClient.CreateFromConnectionString时使用C#的Azure服务总线队列:BadImageFormatException - Azure Service bus Queue using C# : BadImageFormatException when calling QueueClient.CreateFromConnectionString Azure Service Bus - 使用OnMessage()方法接收消息 - Azure Service Bus - Receive Messages with OnMessage() Method Azure 服务总线 - 连续接收消息 - Azure Service Bus - Receive messages continuously Azure Service Bus MessageReceiver Receive()Web套接字错误 - Azure Service Bus MessageReceiver Receive() web sockets error 如何按时间间隔有选择地接收 Azure 服务总线消息? - How to selectively receive Azure Service Bus messages by time interval?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM