1

I'm using WCF with MSMQ endpoints and am seeing the behaviour described in this question - basically although the service is throttled to process one message at a time, 2 messages are taken from the queue, with one seemingly held in memory while the other is being processed.

This presents a problem for monitoring what is happening; I have a monitoring page which shows which jobs are in the queue and which are being processed but due to this behaviour there is a period where a job effectively disappears when it is taken off the queue but hasn't started being processed yet. I'm using MessageQueue.GetAllMessages() to fetch the list of messages currently on the queue.

I'm not that familiar with MSMQ but I assume that when a message is Dequeued it is marked as invisible so that other processes won't take it off. Is there a way to query these messages so I can see what they are?

Community
  • 1
  • 1
Pete S
  • 265
  • 2
  • 11

2 Answers2

1

I can see how that would be annoying especially with low message volumes and a message handler which kicks off a long running process before returning to get the next message.

Semantically speaking, however, when the message disappears off the queue it is actually being processed, it's just that the processing will sometimes involve caching the message for an indefinite time.

As long as you're using transactional queues the hidden message will not be dropped if the service for some reason goes away.

Appreciate that this doesn't answer your question directly.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • Thanks, I've tested the durability and confirmed that the hidden messages are returned to the queue in the event of a service failure. It's just annoying that there isn't a way to get an accurate picture of what is happening. – Pete S Jul 17 '14 at 11:06
  • Yes it's annoying. Welcome to MSMQ. – tom redfern Jul 17 '14 at 13:35
1

If you really want to do that try Peek with a cursor. Sounds like overkill for a monitoring page though.

MessageQueue.Peek on MSDN

You can set it up so that you get the entire message etc, not sure of the performance impact. I have done similar things before...

Paul Kohler
  • 2,684
  • 18
  • 31
  • Does peek allow you to see messages that are being processed? I think I've already tried that but perhaps I did something wrong. Or are you suggesting having something calling peek and waiting on messages to come into the queue? – Pete S Jul 17 '14 at 11:08
  • Yes, exactly that. The cursor stays active and peeks incoming messages. Play around with a POC similar to the msdn example to see if it suits. The timeouts can be fun but you can make it big, it throws on timeout. – Paul Kohler Jul 17 '14 at 12:59
  • Hmm, I guess that could work though it might be tricky as it's an IIS hosted service. I think you are right that it is probably overkill for my monitoring page though. I'll keep it in mind if I don't find another way though. – Pete S Jul 17 '14 at 13:32
  • The hosting in IIS is a separate thing...If you want to quickly see what the peek looks like have a look at MSMQ Inspector (http://viridissoftware.com.au/Products/MSMQInspector) - view a queues messages and turn on the "Constant Peek Mode", it does exactly what we discussed. – Paul Kohler Jul 17 '14 at 22:21