Tags: aspx, etching, getmessages, messageque, messages, msmq, net, que, regarding, run

MSMQ GetMessages

On .Net » .Net Technology

4,577 words with 4 Comments; publish: Fri, 04 Jan 2008 13:46:00 GMT; (10078.13, « »)

Hi, I have a problem regarding etching messages from a messageque. In the que I have over 1000 messages, but I only get 2 messages when I run folowing code:

MessageQueue mq = new MessageQueue("path");

MessageEnumerator myEnumerator = mq.GetMessageEnumerator2();

mq.MessageReadPropertyFilter.Priority = true;

Message message = null;

while(myEnumerator.MoveNext())

{

message = myEnumerator.Current;

myEnumerator.RemoveCurrent();

}

Can someone point me in the right direction please?

All Comments

Leave a comment...

  • 4 Comments
    • Please post this in the MSMQ forum
      #1; Wed, 26 Sep 2007 01:50:00 GMT
    • Im having that same issue. Did you find a solution? I tried using GetAllMessages and then re-adding the ones that didnt match my filter condition, but that only works efficiently with one queue reader. Any advice greatly appreciated. TY.

      #2; Wed, 26 Sep 2007 01:51:00 GMT
    • Liquidmesh Ramblings ( http://liquidmesh.com/blog/blog.aspx ) reports:

      Changed in MSMQ behaviour between GetMessageEnumerator vs GetMessageEnumerator2

      Here's something strange in Microsoft's MSMQ library for .net that I found this week when upgrading from using .net 1.1's GetMessageEnumerator() to .net 2's GetMessageEnumerator2()

      It seems that the two enumerators don't work in the same way.

      With the old version we did this to remove all messages in the queue:

      MessageEnumerator enumerator = queue.GetMessageEnumerator();

      while (enumerator.MoveNext() && messagesProcessed < messagesToProcessBeforeSleep)

      {

      Message message = enumerator.RemoveCurrent();

      messagesProcessed ;

      //...add contents to database

      }

      With the .net 2 version we need to do this:

      MessageEnumerator enumerator = queue.GetMessageEnumerator2();

      while (enumerator.MoveNext() && messagesProcessed < messagesToProcessBeforeSleep)

      {

      Message message = enumerator.RemoveCurrent();

      enumerator.Reset();

      messagesProcessed ;

      //...add contents to database

      }

      If we don't do the enumerator.Reset() the code will only remove one item off the queue before stopping.

      I wonder if anyone else has seen it happen?

      #3; Wed, 26 Sep 2007 01:52:00 GMT
    • I came up against the same problem.

      The way I've solved it, seems to work ok - though it may not be the best. GetAllMessages from the queue doesn't actually remove any messages from the queue. So For example:

      foreach (Message msg in queue.GetAllMessages()) // gets all the messages, but doesn't remove
      {

      }


      Then if my condition within the loop passes (so I 'want' this message - in my case it was a retry timer), I remove the message from the queue based on it's id.

      queue.ReceiveById(msg.Id, mqTrans);

      Otherwise, I just continue in the loop and don't receive. Anyway, hope that helps someone.

      #4; Wed, 26 Sep 2007 01:53:00 GMT