Reading MSMQ message count with ruby

徘徊边缘 提交于 2019-12-23 01:37:16

问题


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


回答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



来源:https://stackoverflow.com/questions/8914813/reading-msmq-message-count-with-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!