views:

204

answers:

3

hi, i am using NServices to send an object of the class MyMusicMessage as blow:

[Serializable]
public class MyMusicMessage:IMessage
{
    public Guid EventId { set; get; }
    public byte[] MusicBytes { set; get; }
}

when the size of MusicBytes is about 200k, it can be sent well.

but when the size is more than 300K,there is a "MessageQueueException".

is there any limit to the object size in NServiceBus?

thanks.

A: 

MSMQ has a limit of 4M. We're working on a databus feature for 2.1 but until then I sugest that you store your music payload "out of band" and only transfer the adress where the data can be picked up in your message.

Hope this helps!

Andreas
thank you, AndreasIn my application, I must transfer the MusicBytes directly.I am expecting more help.
Alidaswe
Can you elaborate on the reason why the data must be transfered with the message?
Andreas
A: 

When using the XML serializer in NServiceBus (which is the default), it will serialize arrays as general purpose collections, creating an entry for each value. It is likely that that is what is causing the actual message size to be much larger than the 300KB in memory.

I suggest you switch to the Binary serializer for that message type.

Udi Dahan
A: 

One thing I noticed when transferring a (much smaller) payload as a byte array is that NServiceBus will serialize it roughly like this (from memory):

<MyByteArray>
    <Byte>4</Byte>
    <Byte>183</Byte>
    <Byte>221</Byte>
    <Byte>87</Byte>
    ...
<MyByteArray>

Obviously not a great way to transfer a byte array efficiently, but I'm sure the NServiceBus serializer is going for speed and efficiency, not the smallest message size possible.

While I agree that it would be best to transfer something as hefty as music data out of band, for smaller byte array payloads (like the 5-10K range) a much better alternative is to encode the byte array as a Base64 string in your message class using Convert.ToBase64String(byte[] arr) and Convert.FromBase64String(string str).

David