views:

83

answers:

1

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?

+1  A: 

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

David
I want to send some binary data (image file). In my specific case this is the only possible way to transfer the image from client to server and I don't wanna to sent that binary data in XML file :)Where did you learn about the recommendation to use one message type per endpoint? Or what do you mean by "message type" then?
mgamer