How to read msmq messages (me, not PC)

I want to look inside my queues, the msm console snpin has this properties dialog box, but it is very difficult to read, and the messages important to me are encoded and look like this:

3C 3F 78 6D 6C 20 76 65 <?xml ve 72 73 69 6F 6E 3D 22 31 rsion="1 2E 30 22 20 65 6E 63 6F .0" enco 64 69 6E 67 3D 22 75 74 ding="ut 66 2D 38 22 3F 3E 0D 0A f-8"?>.. 3C 65 73 62 3A 6D 65 73 <esb:mes 73 61 67 65 73 20 78 6D sages xm 6C 6E 73 3A 65 73 62 3D lns:esb= 22 68 74 74 70 3A 2F 2F "http:// 73 65 72 76 69 63 65 62 serviceb 75 73 2E 68 69 62 65 72 us.hiber 6E 61 74 69 6E 67 72 68 natingrh 

...

Does anyone know of a tool that would allow me to see my posts with a slightly friendly developer? A tool to simplify queue administration will be convenient (for example, select multiple messages and drag them)

+7
msmq
source share
6 answers
+5
source share

Try the following:

 string QueueName = @".\private$\publishingQueue"; //note, you cannot use method exists on remote queues if (MessageQueue.Exists(QueueName)) { var queue = new MessageQueue(queueInfo.QueueName) { MessageReadPropertyFilter = new MessagePropertyFilter { ArrivedTime = true, Body = true } }; var messages = queue.GetAllMessages(); var m = messages[0]; 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(); } //ms now contains the message } 
+2
source share

I found these two methods, looking for the answer to this question, and they really worked perfectly.

  public System.Xml.XmlDocument ConvertToXMLDoc(System.Messaging.Message msg) { byte[] buffer = new byte[msg.BodyStream.Length]; msg.BodyStream.Read(buffer, 0, (int)msg.BodyStream.Length); int envelopeStart = FindEnvolopeStart(buffer); System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer, envelopeStart, buffer.Length - envelopeStart); System.ServiceModel.Channels.BinaryMessageEncodingBindingElement elm = new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement(); System.ServiceModel.Channels.Message msg1 = elm.CreateMessageEncoderFactory().Encoder.ReadMessage(stream, Int32.MaxValue); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(msg1.GetReaderAtBodyContents()); msg.BodyStream.Position = 0; return doc; } private int FindEnvolopeStart(byte[] stream) { int i = 0; byte prevByte = stream[i]; byte curByte = (byte)0; for (i = 0; i < stream.Length; i++) { curByte = stream[i]; if (curByte == (byte)0x02 && prevByte == (byte)0x56) break; prevByte = curByte; } return i - 1; } 

Just call the ConvertToXmlDoc function, providing a message from the message queue, and you will return an XmlDocument. I am lazy, so I just drop innerXml into the file so that I can read it.

  MessageQueue queue = new MessageQueue(queueName); var msg = queue.Receive(); var doc = ConvertToXMLDoc(msg); using (var sw = new StreamWriter(@"C:\message.txt"))) sw.Write(doc.InnerXml); 

There is no app to buy, and you return your data to the code so that you can communicate with it.

PS: Credit, which should be a loan. Excerpt from http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c03d80cd-492c-4ece-8890-6a35b12352e0 , which also refers to a more detailed discussion of the MSMQ encoding format.

+2
source share

If you have only hexadecimal data that can be easily converted to ASCII and vice versa, I suggest a text editor that allows you to do this. UltraEdit has a "view hex" function that works to convert both to and from the hexadecimal representation. You can also try Notepad ++, but I don't know if it has this feature.

0
source share

You can also check out MSMQ Studio http://www.archonaut.se

0
source share

You can use Service Bus MQ Manager, my free open source tool that I wrote to view messages in MSMQ, it supports coloring and formatting of XML and JSON messages.

http://blog.halan.se/page/Service-Bus-MQ-Manager.aspx

0
source share

All Articles