Monitoring empty queues in MSMQ
One common misconception is that because a queue exists in Computer Management you should be able to monitor it.
From the MSMQ FAQ (link on the left):
5.10 ....And why is it that I cannot see all my queues in System Monitor?
... a queue is only monitored if it contains messages or if an application explicitly opened it. Otherwise, the Message Queuing service does not keep any state information for a queue, and it is not available in System Monitor.
Note: The above information also applies to MQMgmtGetInfo API. This API can return state information only regarding active queues. If a queue is not opened by an application and it doesn't contain messages then this API cannot be used to get information on that queue. In that case, MSMQ on Windows Server 2003 will return the error “MQ_ERROR_QUEUE_NOT_ACTIVE” (0xc00e0004). On MSMQ versions that are older than Windows Server 2003 the error returned is “MQ_ERROR” (0xc00e0001).
The main reason for this is that creating data structures for queues that are empty is not an efficient use of resources - and some customers can have hundreds of queues which are empty most of the time.
Common workarounds are:
- Run an application whose sole purpose is to keep all the queues open, forcing MSMQ to maintain performance data for them
- Place a dummy message in the queues that cannot be read. This only works if the main application analyses the messages in the queue to ensure they are what it is looking for. If the application simply reads the first message off the top of the queue then this workaround can't be used.