1

我有一个应用程序将 MongoDB C# 驱动程序 (v1.10.xxx) 创建的 BsonDocuments 作为字节数组写入 RabbitMQ。然后我有另一个应用程序,它使用相同的驱动程序来读取 BsonDocument 的字节表示并将其转换回它的对象形式。

然后,我需要将 MongoDB C# 驱动程序升级到 2.3 版,现在我无法将 RabbitMQ 队列中等待的字节读回BsonDocument,结构仍然存在,但值已经消失。

有人对此有想法吗?

负责写入 RabbitMQ 的代码:

BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
    bf.Serialize(ms, prm_xBsonDocument);
    lock (m_xChannelMessageTrace)
    {
        m_xChannelMessageTrace.QueueBind(m_strQueueNameMessageTrace, m_strExchangeNameCommunication, prm_TraceType.ToString(), null);
        m_xChannelMessageTrace.BasicPublish(m_strExchangeNameCommunication, prm_TraceType.ToString(), null, ms.ToArray());
    }
}

对于阅读,我使用:

var consumer = new EventingBasicConsumer((IModel)property);
consumer.Received += (model, ea) =>
{
    var ms = new MemoryStream(ea.Body);
 
    try
    {
        var formatter = new BinaryFormatter();
        BsonDocument xBsonDocument = ((BsonDocument)formatter.Deserialize(ms));

Writer 应用程序 MongoDB C# 驱动程序版本:v1.10.0.62

阅读器应用程序 MongoDB C# 驱动程序版本:v2.3.0.157

RabbitMQ 记录的开头如下:

\0\0\0\0����\0\0\0\0\0\0\0\f\0\0\0QMongoDB.Bson,版本=1.10.0.62,文化=中性,PublicKeyToken=f686731cfb9cc103 \0\0\0MongoDB.Bson.BsonDocument\0\0\0\t_elements\b_indexes_allowDuplicateNamesBsonValue+ bsonType\0�System.Collections.Generic.List 1[[MongoDB.Bson.BsonElement, MongoDB.Bson, Version=1.10.0.62, Culture=neutral, PublicKeyToken=f686731cfb9cc103]]�System.Collections.Generic.Dictionary2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]MongoDB.Bson.BsonType\0\0\0\0\0\0\t\0\0 \0\t\0\0\0\0����MongoDB.Bson.BsonType\0\0\0\avalue _\0\b\0\0\0\0\0\0\0\0 \0�System.Collections.Generic.List`1[[MongoDB.Bson.BsonElement,MongoDB.Bson,版本=1.10.0.62,文化=中性,...

4

0 回答 0