MSMQ:从远程计算机的MSMQ队列中获取消息的计数
问题描述:
我正在尝试获取远程计算机中特定专用队列的消息数。 我可以从我的本地计算机获取计数。MSMQ:从远程计算机的MSMQ队列中获取消息的计数
LOCALMACHINE:
RemoteMachine:
[email protected]"RemoteMachineName\Private$\Sample";
全码:
当我尝试远程机器路径,它抛出第我e错误无效路径。
如果有人能指导我解决问题,我将不胜感激?
var path ="FormatName:Direct=OS:RemoteMachineName\\private$\\sample";
MessageQueue queuename = new MessageQueue(path);
var mgmt = new MSMQManagement();
object machine = "RemoteMachineName";
object queuename = queue.Path;
object formatname = "Direct=OS";
mgmt.Init(ref machine, ref queuename, ref formatname);
int messageCount = mgmt.MessageCount;
MessageBox.Show(string.Format("Queue has {0} items", messageCount));
答
有三个选项:
- 目标队列不活动状态(即,没有任何消息,而不是通过一个应用程序保持打开)
- 功能无法在远程队列工作(尽管我无法在MSDN中找到此具体名称)
- API调用使用RPC,目标机器阻止RPC调用。
Understanding how MSMQ security blocks RPC traffic
干杯
约翰
答
试试这个代码..
MSMQManagement _manager = new MSMQManagement();
_manager.Init("MACHINE", null, @"DIRECT=OS:MACHINE\PRIVATE$\sample");
Console.WriteLine(_manager.MessageCount);
Marshal.ReleaseComObject(_manager);
答
//strHostName is Machine name/IP from which you have to get queue
//MSMQManagement present in COM library which is present at "C:\Program Files (x86)\Microsoft SDKs\Windows"
PrivateQueueList = MessageQueue.GetPrivateQueuesByMachine(strHostName);
int count = PrivateQueueList.Count();
MSMQManagement QueueManagement = new MSMQManagement[count];
MSMQManagement msmq = null;
int index = 0;
foreach(var queue in PrivateQueueList)
{
msmq = new MSMQManagement();
object machine = queue.MachineName;
object path = null;
object formate=queue.FormatName;
msmq.Init(ref machine, ref path,ref formate);
QueueManagement[index] = msmq;
index++;
}
foreach(var queue in QueueManagement)
{
int count= queue.MessageCount();
Console.WriteLine(queue.QueueName+ " ="+ count);
}
在这里,你得到的所有私人MSMQ消息计数在任何机器是平能。 首先通过ping确认机器是否处于活动状态。 有错误显示如果msmq在.Init方法中有零消息,所以你可以在try catch和catch set count = 0中使用该语句,它会被解决(我知道这是错误的方式,但没有其他方法以处理该错误)。 欲了解更多详情,您可以访问MSDN http://msdn.microsoft.com/en-us/library/ms705997(v=vs.85).aspx
答
这是一个解释片段,我用于远程和本地队列。你需要获得格式名称,但有时候这可能是一种痛苦。
“msmqManagement.Init”下面的参数对我来说不同于你的例子,可能试试。
提示 - 发布实际的异常跟踪,它有所不同。我认为你没有得到“错误无效路径”,堆栈跟踪会为你提供线索,例如计算机名解析问题等
MessageQueue mq = new MessageQueue(path);
var formatName = mq.FormatName;
var msmqManagement = new MSMQManagement();
msmqManagement.Init(machineName, null, formatName);
var messageCount = msmqManagement.MessageCount;
Marshal.ReleaseComObject(msmqManagement);
同样 - 状态是什么版本的MSMQ您使用的是....
大声笑 - 这是帮助我的文章之一! PK :-) –