Skip to content
mookid8000 edited this page Jun 5, 2012 · 6 revisions

Serialization with Rebus consists of transforming a Message into a TransportMessageToSend, and a ReceivedTransportMessage back into a Message.

Here, Message is an object that contains a headers dictionary and multiple logical messages.

TransportMessageToSend and ReceivedTransportMessage are then the physical transport messages, and they contain only headers and a byte[].

As default, Rebus will JSON serialize messages using NewtonSoft JSON.NET.

The choice of serializer

The choice of serializer affects a number of things, expecially when an app needs to deserialize messages! How does it handle different versions of messages? When a field has been removed? When a field has been added? Etc.

This might be a reason why you will not be satisfied with the builtin JSON serializer, because it puts a limit on how much you can affect the serialization process. In this case, you might want to implement your own ISerializeMessages, possibly using one of Rebus' existing serializers as inspiration, and then you're free to do whatever your serialization library will let you do.

Serialization options

If you want to explicitly state which kind of serialization you want, you do it the usual way:

Configure.With(...)
    .Serialization(s => s.UseJsonSerializer())
    //...

or

Configure.With(...)
    .Serialization(s => s.UseBinarySerializer())
    //...

which are currently the only forms of serialization that Rebus includes.

Clone this wiki locally