Peeking an MSMQ Outgoing Queue with JScript

本秂侑毒 提交于 2019-12-13 06:27:41

问题


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.


回答1:


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:

    1. Create a new Generic Application
    2. Resource inside the Group where the MSMQ Service is running, and point it to your Script.
    3. In the Configuration of the new Resource, add the MSMQ Service as a dependence.
    4. Make sure that the checkbox "Use Network Name as Computer Name" is checked.

Done, your script will now connect to the MSMQ Service running inside the Cluster Group.

  • Outgoing Queues are not real Queues, but can be seen as a "list of messages, grouped by the Queue they are destined to". Therefore, they cannot be monitored remotely. This means that, to monitor them, the Script/Application which does it has to be deployed on each machine, and, in a clustered environment, an instance must run in each Cluster Group. This adds a significant overhead if there are many servers, but it can be overcome by creating a centralized system. Big task anyway...

I hope my findings will be useful to somebody in the future. :) Back to pizza baking...



来源:https://stackoverflow.com/questions/3440897/peeking-an-msmq-outgoing-queue-with-jscript

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