我怎样才能在一个MSMQ队列中的所有可用消息 [英] how can i get all the available messages on a MSMQ Queue
问题描述
最新最好的方式来获得当前的所有消息在队列处理?
Whats the best way to get all the messages currently on a queue to process?
我们有一个有大量的非常小的消息队列,我想要做的是读取目前所有的信息关掉,然后通过处理一个线程池发送。
We have a queue with a large number of very small messages, what I would like to do is read all the current messages off and then send them through a thread pool for processing.
我似乎无法找到它会告诉我有什么好的资源怎么可以创建一个简单的方法,返回一个IEnnumerable例如:
I can't seem to find any good resource which will show me how i can create a simple method to return an IEnnumerable for example
感谢
推荐答案
虽然我同意尼克的队列的目的更先进先出的风格处理,并 ArsenMkrt 的解决方案,将工作,另一个选择涉及到使用的 MessageEnumerator 及打桩邮件到您的IEnumerable
Although I agree with Nick that the queue's purpose is more for FIFO style processing, and ArsenMkrt's solution will work, another option involves using a MessageEnumerator and piling the messages into your IEnumerable.
var msgEnumerator = queue.GetMessageEnumerator2();
var messages = new List<System.Messaging.Message>();
while (msgEnumerator.MoveNext(new TimeSpan(0, 0, 1)))
{
var msg = queue.ReceiveById(msgEnumerator.Current.Id, new TimeSpan(0, 0, 1));
messages.Add(msg);
}
这篇关于我怎样才能在一个MSMQ队列中的所有可用消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!