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

半世苍凉 提交于 2020-01-04 04:31:26

问题


I try this: MessageQueue mq = new MessageQueue(".\Journal$"); mq.Purge();

It work good on XP. But, on windows 2003 server, I always have this error : "A workgroup installation computer does not support the operation."


回答1:


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.




回答2:


The correct format for system queues:

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

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

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

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


来源:https://stackoverflow.com/questions/1131384/how-to-purge-msmq-system-queue-journal-programmatically-on-a-workgroup-installat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!