MSMQ接收()方法超时 [英] MSMQ Receive() method timeout

查看:314
本文介绍了MSMQ接收()方法超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从前段时间原来的问题是 MSMQ慢队列中读取,但我公司拥有先进从现在想想我知道这个问题有点多清晰。

My original question from a while ago is MSMQ Slow Queue Reading, however I have advanced from that and now think I know the problem a bit more clearer.

我的code(以及实际上我使用一个开源库的一部分)看起来是这样的:

My code (well actually part of an open source library I am using) looks like this:

queue.Receive(TimeSpan.FromSeconds(10), MessageQueueTransactionType.Automatic);

这是通过使用<一个href="http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.receive%28VS.80%29.aspx">Messaging.MessageQueue.Receive功能和队列是一个MessageQueue。的问题如下。

Which is using the Messaging.MessageQueue.Receive function and queue is a MessageQueue. The problem is as follows.

的code上面一行将被称为指定的超时时间(10秒)。该接收(...)函数是阻塞函数,应该阻塞,直到队列中,此时它会返回一个消息到达。如果没有接收到消息的超时被击中之前,它会返回在超时。如果消息在队列中,当函数被调用时,它会立即返回该消息。

The above line of code will be called with the specified timeout (10 seconds). The Receive(...) function is a blocking function, and is supposed to block until a message arrives in the queue at which time it will return. If no message is received before the timeout is hit, it will return at the timeout. If a message is in the queue when the function is called, it will return that message immediately.

然而,正在发生的事情是接收(...)函数被调用,因为已经有在队列中没有消息,所以等待新消息的到来。当一个新的消息传入(超时之前),所以不检测该新的消息并继续等待。超时最终命中,此时code继续和呼叫接收(...)再次,它拾取消息并处理它。

However, what is happening is the Receive(...) function is being called, seeing that there is no message in the queue, and hence waiting for a new message to come in. When a new message comes in (before the timeout), it isn't detecting this new message and continues waiting. The timeout is eventually hit, at which point the code continues and calls Receive(...) again, where it picks up the message and processes it.

现在,这个问题数天/周后才出现。我可以把它恢复正常,删除和放大器工作;重新创建队列。它发生在不同的计算机和不同的队列。因此,它看起来像是正在建立,直到当它打破了触发/通知的能力某种程度上的接收(...)函数使用。

Now, this problem only occurs after a number of days/weeks. I can make it work normally again by deleting & recreating the queue. It happens on different computers, and different queues. So it seems like something is building up, until some point when it breaks the triggering/notification ability that the Receive(...) function uses.

我查了很多不同的事情,一切似乎正常和放大器;是不是从该正常工作队列不同。有足够的磁盘空间(13gig免费)和RAM(约350MB可用了1GB的从我可以告诉)。我检查了所有出现在同其他队列注册表项和性能监视器不显示任何不正常的。我也运行TMQ工具,什么都看不到从noticably错误。

I've checked a lot of different things, and everything seems normal & isn't different from a queue that is working normally. There is plenty of disk space (13gig free) and RAM (about 350MB free out of 1GB from what I can tell). I have checked registry entries which all appear the same as other queues, and the performance monitor doesn't show anything out of the normal. I have also run the TMQ tool and can't see anything noticably wrong from that.

我使用Windows XP的所有机器,他们都有安装Service Pack 3。我不发送大量消息的队列,至多这将是1,每2秒,但通常很多比较不频繁。这些消息都只是小得无处接近4MB的限制。

I am using Windows XP on all the machines and they all have service pack 3 installed. I am not sending a large amount of messages to the queues, at most it would be 1 every 2 seconds but generally a lot less frequent than that. The messages are only small too and nowhere near the 4MB limit.

我刚才注意到的唯一一件事就是在C p0000001.mq和r0000067.mq文件:\ WINDOWS \ SYSTEM32 \ MSMQ \存储都是4,096KB但他们在其他计算机上也这是目前没有遇到的这种规模问题。该问题不会发生在计算机上的每个队列的一次,因为我可以重新在电脑上1问题队列和其他队列仍然遇到问题。

The only thing I have just noticed is the p0000001.mq and r0000067.mq files in C:\WINDOWS\system32\msmq\storage are both 4,096KB however they are that size on other computers also which are not currently experiencing the problem. The problem does not happen to every queue on the computer at once, as I can recreate 1 problem queue on the computer and the other queues still experience the problem.

我不是非常有经验的MSMQ因此,如果您发布可能需要检查的事项可以请你解释一下如何检查他们或在哪里可以找到更多详细信息,你在说什么。

I am not very experienced with MSMQ so if you post possible things to check can you please explain how to check them or where I can find more details on what you are talking about.

目前的情况是:

  • 在ComputerA - 4个队列正常
  • ComputerB - 2队列遇到的问题,1队列正常
  • ComputerC - 2队列遇到的问题
  • ComputerD - 1队列正常
  • ComputerE - 2队列正常

所以,我有大量的电脑/队列来比较和测试反对。

So I have a large number of computers/queues to compare and test against.

推荐答案

您使用的不是一个事件处理程序以侦听队列任何特别的原因?该System.Messaging库允许您将处理器连接到一个队列,而不是,如果我理解你在做什么正确,循环接收每10秒。尝试是这样的:

Any particular reason you aren't using an event handler to listen to the queues? The System.Messaging library allows you to attach a handler to a queue instead of, if I understand what you are doing correctly, looping Receive every 10 seconds. Try something like this:

class MSMQListener
{
    public void StartListening(string queuePath)
    {
        MessageQueue msQueue = new MessageQueue(queuePath);
        msQueue.ReceiveCompleted += QueueMessageReceived;
        msQueue.BeginReceive();
    }

    private void QueueMessageReceived(object source, ReceiveCompletedEventArgs args)
    {
        MessageQueue msQueue = (MessageQueue)source;

        //once a message is received, stop receiving
        Message msMessage = null;
        msMessage = msQueue.EndReceive(args.AsyncResult);

        //do something with the message

        //begin receiving again
        msQueue.BeginReceive();
    }
}

这篇关于MSMQ接收()方法超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆