Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read message queue sent time from MSMQ Journal

I have an MSMQ with an enabled Journal. And due to the fact that we receive more than 1000 messages per day I want to clear the Journal to keep only the messages from last 2 days. Therfore I want to read all messages and check their SentTime property against the "current date - 2 days". But at the moment the program will stop as the Property SentTime wont be provided.

Error: "PropertyFilter isn't set correctly"

The code:

class Program {

    static void Main(string[] args) {

        string queueName = ".\\private$\\TEST;journal";

        MessageQueue msgQueue = new MessageQueue(queueName);
        Message[] messages = msgQueue.GetAllMessages();

        try{

            foreach (Message msg in messages){
                //if(msg.SentTime < DateTime.Today.AddDays(-2)){
                    Console.WriteLine(msg.SentTime);
                //}
            }

        }catch (Exception e){

            Console.WriteLine(e.Message);

        }

        Console.Read();

    }

}

Why do I have no access to the Property? Who can help? Thanks a lot!

like image 745
Ронни Дрэкслэр Avatar asked May 17 '26 21:05

Ронни Дрэкслэр


1 Answers

You can use

msgQueue.MessageReadPropertyFilter.SetAll();

and it will set all filter properties to true.

like image 182
A J Avatar answered May 19 '26 09:05

A J