简体   繁体   English

如何在工作组安装上以编程方式清除MSMQ系统队列日志?

[英]How to purge MSMQ system queue journal programmatically on a workgroup installation?

I try this: MessageQueue mq = new MessageQueue(".\\Journal$"); 我试试这个:MessageQueue mq = new MessageQueue(“。\\ Journal $”); mq.Purge(); mq.Purge();

It work good on XP. 它在XP上运行良好。 But, on windows 2003 server, I always have this error : "A workgroup installation computer does not support the operation." 但是,在Windows 2003服务器上,我总是有这样的错误:“工作组安装计算机不支持该操作。”

The correct format for system queues: 系统队列的正确格式:

FormatName:Direct=os:.\\System$;JOURNAL

I've tested this format on Windows 7 and Windows 2003. 我在Windows 7和Windows 2003上测试过这种格式。

(the dot after os: means the localhost/local computer) (os之后的点:表示本地主机/本地计算机)

var systemJournalQueue = new MessageQueue("FormatName:Direct=os:.\\System$;JOURNAL");
var systemDeadLetterQueue = new MessageQueue("FormatName:Direct=os:.\\System$;DEADLETTER");
var systemDeadXLetterQueue =new MessageQueue("FormatName:Direct=os:.\\System$;DEADXACT"));

systemJournalQueue.Purge();

or if you want to keep N days of messages you can do this: 或者如果你想保留N天的消息,你可以这样做:

private static void PurgeQueues(int archiveAfterHowManyDays, MessageQueue queue)
{
    queue.Formatter = new XmlMessageFormatter(new Type[] { typeof(System.String) });
    queue.MessageReadPropertyFilter.ArrivedTime = true;

    using (MessageEnumerator messageReader = queue.GetMessageEnumerator2())
    {
        while (messageReader.MoveNext())
        {
            Message m = messageReader.Current;
            if (m.ArrivedTime.AddDays(archiveAfterHowManyDays) < DateTime.Now)
            {
                queue.ReceiveById(m.Id);
            }
        }
    }
}

Try using format name like so: 尝试使用格式名称,如下所示:

MessageQueue mq = new MessageQueue("DIRECT=OS:computername\SYSTEM$;JOURNAL");
mq.Purge();

I think that system queue can't be access by path. 我认为系统队列不能通过路径访问。 You have to use format name. 您必须使用格式名称。

look at Yoel Arnon's comment at the bottom of the page. 看看Yoel Arnon在页面底部的评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM