简体   繁体   中英

MSMQ - can I query messages which are currently being processed?

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?

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM