1

I've got a problem querying the message count from the remote msmq queue.

This is my code:

def get_message_count
    mq_management = WIN32OLE.new('MSMQ.MSMQManagement')
    mq_management.Init('xxx.yyy.zz.aa', nil,'direct=tcp:xxx.yyy.zz.aa\private$\inbox')
    message_count = mq_management.MessageCount
end

xxx.yyy.zz.aa is the IP Address of the remote computer.

This method actually works as a charm, BUT:

  1. if the queue is empty, then I keep getting this error after certain amount of time:

    `method_missing': Init (WIN32OLERuntimeError) OLE error code:C00E0004 in MSMQManagement The queue is not open or may not exist. HRESULT error code:0x80020009 Exception occurred.

  2. if there are still items in the queue then this method works as it supposed to.

I found this article: How do I create an MSMQ outgoing queue? which says:

MSMQ keeps the queue alive (even if it is empty) for a few minutes just in case you are going to send another message. This saves the queue manager the effort of making the network connection again. This cleanup delay is controlled by the CleanupInterval registry value - 5 minutes for clients and 2 minutes for servers.

It is currently not an option for us to tweak the registry settings. Another option would probably be to try getting the message count through WMI but I am not sure how you do this in ruby (being a .NET developer)

Maybe there is a possibility to "wake up" the queue?

I would appreciate any help! Thank you

Community
  • 1
  • 1
Helikaon
  • 1,490
  • 13
  • 30

1 Answers1

1

For efficiency, MSMQ doesn't maintain performance data on queues that are:

  1. Empty, and
  2. Closed

You could, for example, have a machine with 1,000s of empty queues which would lock up memory resources if such data was actively maintained. Effectively, empty queues don't exist as things to analyse until they have been opened by an application.

My blog post about outgoing queues has nothing to do with this situation as you are querying information about a private queue.

Cheers John Breakwell

John Breakwell
  • 4,667
  • 20
  • 25
  • 1
    Hi John, thanks for your answer. This issue with message queues consuming to much resources is well understood by me now. However this part: "Effectively, empty queues don't exist as things to analyse until they have been opened by an application." presents a bit of a problem. Querying an "inactive" message queue results in the same exception as when the server is unreachable. so it is difficult to tell what the cause is. If empty queues "effectively don't exist" then it shouldn't be possible to analyse the performance counters for this queue though. is it really impossible? – Helikaon Jan 18 '12 at 20:51
  • Simple test: Load Performance Monitor and try to add an instance of the "MSMQ Queue\Messages in queue" object. The list of queues you can select from will NOT include empty/inactive queues. – John Breakwell Jan 18 '12 at 22:35
  • One workaround has been to put a message in each queue that the receiving application never reads. This "keepalive" message ensures the queue shows up for performance monitoring. Obviously doesn't work for applications that just automatically receive messages off the top of the queue. – John Breakwell Jan 18 '12 at 22:37
  • 1
    Hey John, thanks for confirming the absence of the performance counter in case the queue is not being used. I've just checked this myself (yesterday I was already at home). The interesting thing I have just stumbled upon is that in case the queue is empty BUT the application is still receiving from the queue (queue.Receive(timeout)) you still can check the message count. this kinda solves my problem because in our automated deployment (using ruby) we check the count before stopping the windows service. the case that the service have already been stopped before is also handled. Cheerz – Helikaon Jan 19 '12 at 07:34
  • That's expected behaviour - if an application has an open handle on a queue (which can be empty or not) then MSMQ will generate performance data. – John Breakwell Jan 19 '12 at 14:35