3

Background:
C# WPF application talking to JAVA server running on linux via ActiveMQ(Apache.NMS) / JSON(Newtonsoft.Json)

Problem:
JSON messages greater than 85000 bytes lead to LOH fragmentation

Possible solution:
Instead of reading the JSON as an Apache.NMS.ITextMessage (which is currently the case), get the underlying stream handle and deserialize using JsonTextReader

Implementation issues:
It would appear that this is not supported by Apache.NMS API although there are ActiveMQStreamMessage/ActiveMQBytesMessage variants which doesn't really fit the bill here.

I would like to know if anybody has got any experience on above?

Rookie
  • 49
  • 3

1 Answers1

0

Well, if you agree to skip the "pure" NMS api and access the ActiveMQ classes, you can get a handle to a MemoryStream via the public Content property. There may be compression you need to deal with though.

                    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
Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84