read message queue sent time from MSMQ Journal

[Originally posted by]: http://stackoverflow.com/questions/14828430/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!

shareedit

You can use

msgQueue.MessageReadPropertyFilter.SetAll();

and it will set all filter properties to true.

shareedit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s