Querying MSMQ Messages Using LINQ

In a project that I’m currently working on, I needed to retrieve messages from MSMQ based on some criteria, I used LINQ to do that and would like to share this code with you. MessageQueue messageQueue = new MessageQueue(Constants.MessageQueueName); messageQueue.Formatter = new BinaryMessageFormatter(); var TrackingRecords = from System.Messaging.Message message in messageQueue where message.Label.Contains(Constants.MessageLabel) select (ICLGRecord)message.Body; // Itterate through the Messages foreach (var TrackingRecord in TrackingRecords) { } // Remove All Items From MSMQ messageQueue.Purge();

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