用Ruby读取MSMQ消息计数 [英] Reading MSMQ message count with ruby

查看:92
本文介绍了用Ruby读取MSMQ消息计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从远程msmq队列查询消息数时遇到问题.

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

这是我的代码:

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是远程计算机的IP地址.

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

这种方法实际上是一种魅力,但是:

This method actually works as a charm, BUT:

  1. 如果队列为空,那么经过一定时间后我仍然会收到此错误:

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

`method_missing':初始化(WIN32OLERuntimeError) MSMQManagement中的OLE错误代码:C00E0004 队列未打开或可能不存在. HRESULT错误代码:0x80020009 发生异常.

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

如果队列中仍然有项目,则此方法将按预期工作.

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将队列保持活动状态(即使它为空)几分钟,以防万一您要发送另一条消息.这节省了队列管理器重新建立网络连接的精力.此清除延迟由CleanupInterval注册表值控制-客户端5分钟,服务器2分钟.

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.

当前,我们无法调整注册表设置. 另一种选择可能是尝试通过WMI获取消息计数,但是我不确定您是如何在ruby中做到这一点的(作为.NET开发人员)

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?

我将不胜感激! 谢谢

推荐答案

为了提高效率,MSMQ不在以下队列中维护性能数据:

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

  1. 空,
  2. 关闭

例如,您可能有一台具有1000个空队列的计算机,如果主动维护此类数据,它们将锁定内存资源.实际上,只有在应用程序打开空队列之后,才将空队列作为要分析的事物.

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.

欢呼 约翰·布雷克威尔(John Breakwell)

Cheers John Breakwell

这篇关于用Ruby读取MSMQ消息计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆