Skip to content

Instantly share code, notes, and snippets.

@rod-dot-codes
Created October 31, 2013 09:45
Show Gist options
  • Save rod-dot-codes/7247055 to your computer and use it in GitHub Desktop.
Save rod-dot-codes/7247055 to your computer and use it in GitHub Desktop.
Read the last message of a C# Queue
MessageQueue queue = new MessageQueue("FormatName:DIRECT=OS:<queue_address>")
{
MessageReadPropertyFilter = new MessagePropertyFilter
{
ArrivedTime = true,
Body = true
}
};
Console.WriteLine(queue.CanRead.ToString());
Console.WriteLine(queue.CanWrite.ToString());
var messages = queue.GetAllMessages();
var m = messages.Last();
m.Formatter = new System.Messaging.XmlMessageFormatter(new String[] {});
StreamReader sr = new StreamReader(m.BodyStream);
string ms = "";
string line;
while (sr.Peek() >= 0)
{
ms += sr.ReadLine();
}
Console.Write(HttpUtility.HtmlDecode(ms));
@rod-dot-codes
Copy link
Author

Oh ya, requires you to import

System.Messaging
System.Web

and import the relative DLL's in LinqPad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment