NServiceBus 为某些消息类型指定 BinarySerializer,但不是为所有消息类型指定 BinarySerializer

发布于 2024-09-01 07:45:31 字数 152 浏览 1 评论 0原文

NServiceBus 2.0 是否允许为给定消息类型定义序列化器?

我希望使用 XmlSerializer 对除一条消息之外的所有消息进行序列化。剩下的一个应该使用 BinarySerializer 进行序列化。

NServiceBus 2.0 可以吗?

Does NServiceBus 2.0 allow for defining serializer for given message type?

I want for all but one of my messaages to be serialized using XmlSerializer. The remaining one should be serialized using BinarySerializer.

Is it possible with NServiceBus 2.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

殊姿 2024-09-08 07:45:31

我相信序列化器是在端点的基础上指定的,因此使用该端点的所有消息都将使用相同的序列化器。

但是,如果您遵循 NServiceBus 的死记硬背建议:每个端点/队列使用一种消息类型,那么您可以有效地隔离一种消息类型并为其使用不同的序列化程序。

然而,我很好奇,需要二进制序列化的一种消息类型有什么特别之处?

编辑回应评论

分销商信息在路由下间接提到了这一点与经销商。 Udi Dahan 也经常在 NServiceBus Yahoo Group 中提出这一建议,尽管很难提供链接因为那里的搜索很差。

基本上,这个想法是,您不希望高优先级消息被困在低优先级消息后面,而且这为您提供了最大的灵活性,可以在必要时扩展某些消息处理。

由于 MsmqTransportConfig 只允许指定一个 InputQueue,因此每个队列拥有一种消息类型也意味着每个端点只有一个消息处理程序。

要寻址图像,如果将字节数组编码为 Base64 编码的字符串,您仍然可以将其封装在 XML 格式的消息中。这并不理想,但如果您的图像不太大,那么这样做可能比只在一种消息类型上使用不同的序列化程序更容易。

另一种选择是将带外图像数据存储在数据库或文件系统中,然后通过 ID 或路径(分别)引用它。

I believe the serializer is specified on an endpoint basis, so all messages using that endpoint would use the same serializer.

However, if you follow the rote NServiceBus recommendation of one message type per endpoint/queue then you could effectively isolate one message type and use a different serializer for it.

I'm curious, however, what is special about the one message type that requires binary serialization?

Edit in response to comment

The Distributor info indirectly mentions this under Routing with the Distributor. Udi Dahan also frequently advises this in the NServiceBus Yahoo Group although it's difficult to provide links because the search there is poor.

Basically, the idea is that you wouldn't want high priority messages to get stuck behind lower-priority ones, and also that this provides you with the greatest flexibility to scale out certain message processing if necessary.

Because the MsmqTransportConfig only allows for one InputQueue to be specified, having one message type per queue also means that you only have one message handler per endpoint.

To address the image, you may still be able to encapsulate it in an XML-formatted message if you encode the byte array as a Base64-encoded string. It's not ideal, but if your images aren't too large, it may be easier to do this than to go to the trouble of using a different serializer on only one message type.

Another option is to store the image data out-of-band in a database or filesystem and then refer to it by an ID or path (respectively).

我还不会笑 2024-09-08 07:45:31

在版本 2 中不可能。但可以使用版本 5 及更高版本中的管道来完成 http ://docs.pspecial.net/samples/pipeline/multi-serializer/

Not possible in Version 2. But it can be done using the pipeline in versions 5 and above http://docs.particular.net/samples/pipeline/multi-serializer/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文