Reading MSMQ message count with ruby

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

ruby
msmq
windows-server
asked on Stack Overflow Jan 18, 2012 by Helikaon • edited Jun 20, 2020 by Community

1 Answer

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

answered on Stack Overflow Jan 18, 2012 by John Breakwell

User contributions licensed under CC BY-SA 3.0