gpt4 book ai didi

msmq - 如何从队列中读取 MSMQ 消息对象作为消息正文的字符串

转载 作者:行者123 更新时间:2023-12-04 00:47:58 26 4
gpt4 key购买 nike

是否可以直接从队列中以字符串形式读取消息(与您在计算机管理 MSC 管理单元中查看 MSMQ 消息时看到的消息正文相同),以便我可以自己将其保存到数据库中?我希望能够存储它以便稍后重播而不会丢失任何数据,我担心如果反序列化/序列化它我可能会丢失一些东西。

最佳答案

试试这个..

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
}

关于msmq - 如何从队列中读取 MSMQ 消息对象作为消息正文的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4810162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com