【问题标题】:How to read msmq messages (me, not the pc)如何阅读 msmq 消息(我,不是电脑)
【发布时间】:2011-02-27 01:43:00
【问题描述】:

我想查看我的队列,msm 控制台管理单元有这个属性对话框,但它很难阅读,对我来说很重要的消息被编码并且看起来像这样:

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

...

任何人都知道可以让我以对开发人员友好的方式查看我的消息的工具吗?一个便于管理队列的工具会派上用场(比如选择多条消息并拖放它们)

【问题讨论】:

    标签: msmq


    【解决方案1】:

    【讨论】:

    • 嗯,看起来不错 - 但我只能看到我的日记子队列 - 你认为这是因为我不是注册用户吗?
    • 我没有试用版,但在我的完整版中,我可以探索所有队列,包括远程队列。
    • 他们现在有了一个可以理解子队列的新测试版。到目前为止,我正在使用它。有点错误(嗯,测试版),但是一个非常有用的工具。我想知道为什么 MS 不能想出更好的东西。
    • 乍一看很棒,比 Windows 中的计算机管理实用程序好得多。 +1
    【解决方案2】:

    如果您只有一些可以轻松转换为 ASCII 并返回的十六进制数据,那么我建议您使用文本编辑器来执行此操作。 UltraEdit 有一个“查看十六进制”功能,可以在十六进制视图之间进行转换。你也可以试试记事本++,但我不知道它是否有这个功能。

    【讨论】:

    • 属性对话框只显示前n行以及解码后的文本。我怀疑我可以用这些做任何事情。
    • 哦,对了,我没有意识到您没有访问更多数据的权限。
    【解决方案3】:

    您也可以通过https://msmq-studio.com查看 MSMQ Studio

    【讨论】:

      【解决方案4】:

      试试这个:

      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      
      }
      

      【讨论】:

        【解决方案5】:

        我在寻找这个问题的答案时发现了这两种方法,它们实际上工作得很好。

            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;
            }
        

        只需调用 ConvertToXmlDoc 函数,从消息队列中提供消息,您就会得到一个 XmlDocument。我很懒,所以我只是把 innerXml 放到一个文件中,这样我就可以阅读它了。

            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);
        

        无需购买任何应用程序,您就可以在代码中恢复数据,以便您随意处理它。

        PS:信用到期。 sn-p 来自 http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c03d80cd-492c-4ece-8890-6a35b12352e0 ,它还链接到对 MSMQ 编码格式的更详细讨论。

        【讨论】:

          【解决方案6】:

          您可以使用 Service Bus MQ Manager,它是我为在 MSMQ 中查看消息而编写的免费开源工具,它支持 XML 和 JSON 消息的着色和格式化。

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2017-03-04
            • 1970-01-01
            • 1970-01-01
            • 2017-11-20
            • 1970-01-01
            • 1970-01-01
            • 2021-10-12
            相关资源
            最近更新 更多