How to read msmq messages (me, not the pc)

前端 未结 6 1801
梦如初夏
梦如初夏 2021-02-20 02:25

I want to look inside my queues, the msm console snapin has this property dialog, but it is very difficult to read and the messages which are important to me are encoded and loo

6条回答
  •  青春惊慌失措
    2021-02-20 02:53

    Try this:

    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      
    }
    

提交回复
热议问题