【问题标题】:Query MSMQ System Queues in C#在 C# 中查询 MSMQ 系统队列
【发布时间】: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


    【解决方案1】:

    因此,系统队列的实例无法访问 MessageQueue 类的某些属性。 QueueName 就是其中之一!

    我最终使用自定义方法 GetSystemQueuesByMachine 创建了一个自定义类 SystemMessageQueue。这将返回具有自定义名称的 MessageQueue 实例,我使用这些名称填充 ListView,并且我仍然可以对 MessageQueue 实例使用 GetAllMessages()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-17
      • 2010-11-06
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 2011-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多