开发者

NServiceBus sending data question

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

[Serializable]
public class MyMusicMess开发者_JAVA技巧age: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.


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


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜