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

2

3

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."

Indenture answered 15/7, 2009 at 13:24 Comment(0)
P
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.

Parvenu answered 17/7, 2009 at 21:19 Comment(1)
This is incorrect, the code won't even compile, (because of the backslash), see my answer for the correct syntax (your link did give me the proper answer, however).Daisydaitzman
D
5

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);
            }
        }
    }
}
Daisydaitzman answered 11/5, 2012 at 22:22 Comment(0)
P
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.

Parvenu answered 17/7, 2009 at 21:19 Comment(1)
This is incorrect, the code won't even compile, (because of the backslash), see my answer for the correct syntax (your link did give me the proper answer, however).Daisydaitzman

© 2022 - 2024 — McMap. All rights reserved.