【发布时间】:2014-10-06 16:26:17
【问题描述】:
我使用 System.Messaging 命名空间的非常方便的 GetPrivateQueuesByMachine 和 GetPublicQueuesByMachine 方法。我找不到等效的 GetSystemQueuesByMachine,所以我自己写了:
private MessageQueue[] GetSystemQueuesByMachine(string hostName)
{
MessageQueue[] queueList = new MessageQueue[3];
// System Journal
string queuePath = GetQueuePath(hostName, "system$;JOURNAL");
queueList[0] = new MessageQueue(queuePath);
// Get the Dead Letter queue
queuePath = GetQueuePath(hostName, "system$;DEADLETTER");
queueList[1] = new MessageQueue(queuePath);
// Transactional Dead Letter Queue
queuePath = GetQueuePath(hostName, "system$;DEADXACT");
queueList[2] = new MessageQueue(queuePath);
return queueList;
}
private static string GetQueuePath(string hostName, string queueName)
{
return "FormatName:DIRECT=OS:" + hostName + @"\" + queueName;
}
返回的 queuePath 看起来正确:
"FormatName:DIRECT=OS:localhost\system$;JOURNAL"
但是当我尝试访问 QueueName 属性或调用 GetAllMessages() 方法时抛出异常:
"指定的格式名不支持请求的操作,例如不能删除直接队列格式名。"
知道如何以编程方式检索系统队列的内容(系统日志、死信和事务性死信)吗?
【问题讨论】:
标签: c# message-queue msmq