Question

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.).

Was it helpful?

Solution

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));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top