如何清除MSMQ系统队列日志编程? [英] How to purge a MSMQ system queue journal programatically?

查看:1237
本文介绍了如何清除MSMQ系统队列日志编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要批量的系统队列日志每周清洗。

Need to batch a weekly purge of the System queue journal.

推荐答案

有关系统队列的正确格式为:

The correct format for system queues:

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

我已经在Windows 7和Windows 2003中测试这种格式。

I've tested this format on Windows 7 and Windows 2003.

(OS后点:指本地主机/本地计算机)

(the dot after os: means the localhost/local computer)

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();

如果你想保持N天的邮件,你可以这样做:

or if you want to keep N days of messages you can do this:

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())
    {
        int counter = 0;
        while (messageReader.MoveNext())
        {
            Message m = messageReader.Current;
            if (m.ArrivedTime.AddDays(archiveAfterHowManyDays) < DateTime.Now)
            {
                queue.ReceiveById(m.Id);
                counter++;
            }
        }
    }
}

这篇关于如何清除MSMQ系统队列日志编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆