How to programmatically clear the MSMQ system queue log when setting up a workgroup?

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

This works well on XP. But on a Windows 2003 server, I always have this error: "The workgroup setup computer does not support the operation."

+3
source share
2 answers

Try using the format name like this:

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

I think the system queue may not be available along the way. You must use the format name.

see the comment by Yoel Arnon at the bottom of the page.

+1
source

The correct format for system queues is:

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

I tested this format on Windows 7 and Windows 2003.

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

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);
            }
        }
    }
}
+5

All Articles