使用 JScript 查看 MSMQ 传出队列
我创建了一个脚本来监视一组队列,虽然它与远程专用队列完美配合,但它不适用于传出队列。我做了一个实验,从脚本中删除了除必要内容之外的所有内容,并创建了以下测试脚本:
var info = new ActiveXObject("MSMQ.MSMQQueueInfo");
info.FormatName = /*<Queue name>*/;
// 0x80 = MQ_ADMIN_ACCESS
// 0x20 = MQ_PEEK_ACCESS
// 0x00 = MQ_DENY NONE
var mq = info.Open(0x80 | 0x20, 0x00);
var msg = mq.PeekCurrent(false, true, 0);
if (msg != null) {
WScript.echo("message found");
}
else
{
WScript.echo("Nothing");
}
mq.close();
然后我在服务器上运行它,即使队列包含超过一千条消息,PeekCurrent 始终返回空值。如果我删除 MQ_ADMIN_ACCESS,它会尝试连接到远程专用队列并超时(如预期,因为它会导致消息累积)。如果我随后启动远程专用队列,它会从中正确读取消息。
出于好奇,我发现当使用 MQ_ADMIN_ACCESS 时,无论队列名称(即是否存在),info.Open 总是成功。例如,我输入“DIRECT=OS:Whatever\private$\RandomQueueName”,但没有收到任何错误。
我不是 MSMQ 专家(恰恰相反),所以我可能犯了一个明显的错误,但我看不到它。非常欢迎任何帮助。谢谢。
附带问题:是否可以查看远程传出队列?目前,该脚本正在我正在测试的传出队列所在的计算机上运行,但它并不是唯一具有这些队列的计算机。我想避免在任何地方部署脚本,我宁愿将其放在一个地方。谢谢。
I created a script to monitor a set of queues, and, while it works perfectly with Remote Private Queues, it doesn't work with Outgoing Queues. I made an experiment by removing everything but the essential from the script, and I created the following test script:
var info = new ActiveXObject("MSMQ.MSMQQueueInfo");
info.FormatName = /*<Queue name>*/;
// 0x80 = MQ_ADMIN_ACCESS
// 0x20 = MQ_PEEK_ACCESS
// 0x00 = MQ_DENY NONE
var mq = info.Open(0x80 | 0x20, 0x00);
var msg = mq.PeekCurrent(false, true, 0);
if (msg != null) {
WScript.echo("message found");
}
else
{
WScript.echo("Nothing");
}
mq.close();
I then ran it on the server and, even if the queue contains over a thousand messages, PeekCurrent always returns null. If I remove MQ_ADMIN_ACCESS it tries to connect to the Remote Private Queue and it times out (as expected, as it's down to let messages cumulate). If I then start the Remote Private Queue, it reads the message correctly from it.
Out of curiosity, I found out that info.Open always succeeds no matter the Queue Name (i.e. whether it exists or not) when MQ_ADMIN_ACCESS is used. For example, I typed "DIRECT=OS:Whatever\private$\RandomQueueName", and I didn't get any error.
I'm not an expert of MSMQ (quite the opposite), so I'm probably making an obvious mistake and I can't see it. Any help is more than welcome. Thanks.
Side question: is it possible to peek a Remote Outgoing Queue? At the moment the script is running on the machine where the Outgoing Queue I'm testing is located, but it's not the only one with these queues. I'd like to avoid deploying the script everywhere, I'd prefer to have it in a single place. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了两个问题的答案:
我遇到的问题是由于我尝试监视作为群集资源组的一部分运行的 MSMQ 队列,而脚本在当前控制台下运行会议。要访问集群资源组内的队列,必须执行以下操作:
完成后,您的脚本现在将连接到在群集组内运行的 MSMQ 服务。
我希望我的发现对将来的人有用。 :)
回到披萨烘焙……
I found the answers to both my questions:
The issue I was having was due to the fact that I tried to monitor an MSMQ Queue which was running as part of a Cluster Resource Group, while the script was running under the current Console Session. To access a Queue inside a Cluster Resource Group, the following must be done:
Done, your script will now connect to the MSMQ Service running inside the Cluster Group.
I hope my findings will be useful to somebody in the future. :)
Back to pizza baking...