我正在尝试将大对象 (>30MB) 发送到 MSMQ 队列。由于我们要发送的数据量很大,因此我们的想法是在发送对象之前对对象进行 GZip,然后在接收端解压缩它们。
但是,将压缩流写入message.BodyStream
属性似乎可行,但不能从那里读取。我不知道怎么了。
Message l_QueueMessage = new Message();
l_QueueMessage.Priority = priority;
using (MessageQueue l_Queue = CreateQueue())
{
GZipStream stream = new GZipStream(l_QueueMessage.BodyStream, CompressionMode.Compress);
Formatter.Serialize(stream, message);
l_Queue.Send(l_QueueMessage);
}
Formatter 是 BinaryFormatter 类型的全局属性。这用于序列化/反序列化为我们想要发送/接收的对象类型,例如“ProductItem”。
接收端如下所示:
GZipStream stream = new GZipStream(l_Message.BodyStream, CompressionMode.Decompress);
object decompressedObject = Formatter.Deserialize(stream);
ProductItem l_Item = decompressedObject as ProductItem;
m_ProductReceived(sender, new MessageReceivedEventArgs<ProductItem>(l_Item));
l_ProductQueue.BeginReceive();
我EndOfStreamException "{"Unable to read beyond the end of the stream."}
试图在 System.IO.BinaryReader.ReadByte() 处反序列化
使用 messageBodyStream 属性,我实际上绕过了 message.Formatter,我没有初始化任何东西,因为我在 GZipStream 中使用了我自己的 ser/deser 机制。但是,我不确定这是否是正确的方法。
我错过了什么?谢谢!