4

When I receive a ActiveMQBytesMessage, the Content property has exactly the expected length, but all bytes are zero, it looks like an uninitialized buffer with just the correct length.

I also tried ReadBytes(buffer, length) on the message object, and got the same empty buffer.

I'm pretty sure that the messages arrives correctly at the broker, because I can look into the XML representation of the message via the ActiveMQ web interface, and there I can see the correct Base64 representation in <content><data>

I'm using the latest version 1.5.6.

Any ideas what I might be doing wrong?

Update

How I create the message before sending it using a publisher:

var binMessage = new ActiveMQBytesMessage();
binMessage.Content = /* ... */

This is what a message looks like on the web interface (queue browser):

<org.apache.activemq.command.ActiveMQBytesMessage>
  <commandId>5</commandId>
  <!-- ... -->
  <content>
    <data>H4sIAN[...]AA=</data>
    <offset>0</offset>
    <length>305</length>
  </content>
  <!-- ... -->
</org.apache.activemq.command.ActiveMQBytesMessage>

This is what I basically do in my MessageListener:

Console.WriteLine("Message ID: " + message.NMSMessageId);
var bytesMessage = message as IBytesMessage;
if (bytesMessage != null)
{
    Console.WriteLine("Content length: " + bytesMessage.Content.Length);
    Console.WriteLine("Content: " + BitConverter.ToString(bytesMessage.Content));
}

This gives me the correct content length, but the actual content is just empty (hex output is just 00-00-00 etc.).

realMarkusSchmidt
  • 4,303
  • 1
  • 29
  • 33
  • Try adding some actual code, and or more details. Not enough here to really help you. – Tim Bish Jun 12 '13 at 19:42
  • Thank you very much for your fast response! Can you get enough details from the updated question? Handling of connections, publishers, consumers, sessions etc. should be fine since the solution has already successfully processed many million text messages :) This problem only occured with the Bytes Message. – realMarkusSchmidt Jun 12 '13 at 20:15

1 Answers1

3

I believe this is working as its currently designed. The Content field is read and returned to you by the first call to Content where you display the length. At this point the message is now read to the end of its data stream. Before you can call Content again and re-read the data you need to reset the message.

Something like this should work.

Console.WriteLine("Message ID: " + message.NMSMessageId);
var bytesMessage = message as IBytesMessage;
if (bytesMessage != null)
{
    byte[] content = bytesMessage.Content;
    Console.WriteLine("Content length: " + content.Length);
    Console.WriteLine("Content: " + BitConverter.ToString(content));
}
Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • Thank you very much, that did the trick :) Just if you get the chance to do an API refactoring in the future, I would suggest to back the property by a buffer, or instead of a property offer only the `ReadBytes` which makes this behavior a little more expected. According to "Microsofts Property Design Guidelines", properties should not "produce side effects". "Property getters should be simple operations without any preconditions." ;) http://msdn.microsoft.com/en-us/library/ms229006(v=vs.80).aspx – realMarkusSchmidt Jun 13 '13 at 09:16
  • I'm not a Microsoft fanboy so I don't generally follow their guidelines. If you want some improvements please open an issue with the project and attach a patch and tests. – Tim Bish Jun 13 '13 at 10:29