【问题标题】:How to get the underlying Stream handle from an Apache NMS ActiveMQ message如何从 Apache NMS ActiveMQ 消息中获取底层 Stream 句柄
【发布时间】:2015-07-10 09:17:44
【问题描述】:

背景:
C# WPF 应用程序通过 ActiveMQ(Apache.NMS) / JSON(Newtonsoft.Json) 与在 Linux 上运行的 JAVA 服务器通信

问题
大于 85000 字节的 JSON 消息导致 LOH 碎片

可能的解决方案:
而不是将 JSON 作为 Apache.NMS.ITextMessage 读取(目前是这种情况), 使用 JsonTextReader 获取底层流句柄并反序列化

实施问题:
尽管 Apache.NMS API 似乎不支持此功能 有 ActiveMQStreamMessage/ActiveMQBytesMessage 变体 不适合这里的账单。

我想知道有没有人有以上经验?

【问题讨论】:

    标签: c# .net activemq nms apache-nms


    【解决方案1】:

    好吧,如果您同意跳过“纯”NMS api 并访问 ActiveMQ 类,您可以通过公共 Content 属性获得 MemoryStream 的句柄。不过,您可能需要处理一些压缩问题。

                        ITextMessage msg = consumer.Receive () as ITextMessage;
                        ActiveMQTextMessage tmsg = msg as ActiveMQTextMessage;
                        Stream stream = new MemoryStream(tmsg.Content);
    
                        if(tmsg.Compressed == true)
                        {
                            stream = tmsg.Connection.CompressionPolicy.CreateDecompressionStream(stream);                            
                        }
    
                        // TODO read MemoryStream to whatever
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-21
      • 2011-03-07
      • 2018-05-13
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      相关资源
      最近更新 更多