NServiceBus发送数据问题
我正在使用NServices发送MyMusicMessage类的对象,如下所示:
[Serializable]
public class MyMusicMessage:IMessage
{
public Guid EventId { set; get; }
public byte[] MusicBytes { set; get; }
}
当MusicBytes的大小约为200k时,可以很好地发送。
但是当大小超过300K时,就会出现“MessageQueueException”。
NServiceBus 中的对象大小有限制吗?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当将(小得多)有效负载作为字节数组传输时,我注意到的一件事是,NServiceBus将大致像这样序列化它(从内存中):
显然不是有效传输字节数组的好方法,但是我确信 NServiceBus 序列化器追求的是速度和效率,而不是尽可能小的消息大小。
虽然我同意最好将像音乐数据这样大的数据传输到带外,但对于较小的字节数组有效负载(例如 5-10K 范围),更好的选择是将字节数组编码为消息中的 Base64 字符串使用Convert.ToBase64String(byte[] arr) 和Convert.FromBase64String(string str) 的类。
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):
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)
andConvert.FromBase64String(string str)
.当在 NServiceBus 中使用 XML 序列化程序(默认)时,它将序列化数组作为通用集合,为每个值创建一个条目。这很可能是导致实际消息大小远大于内存中 300KB 的原因。
我建议您切换到该消息类型的二进制序列化器。
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 的限制为 4M。我们正在开发 2.1 的数据总线功能,但在此之前我建议您将音乐负载存储在“带外”,并且仅传输可以在消息中获取数据的地址。
希望这有帮助!
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!