Skip to content
Mogens Heller Grabe edited this page Oct 13, 2022 · 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. It is capable of doing this without referencing any additional packages because it has had Newtonsoft JSON.NET IL-merged in.

The choice of serializer

The choice of serializer affects a number of things, especially 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 select another serializer, bring in one of the several serialization packages - e.g. Rebus.NewtonsoftJson:

// use your own awesome settings here
var settings = new JsonSerializerSettings { ... }

Configure.With(...)
    .Serialization(s => s.UseNewtonsoftJson(settings))
    //...

or Rebus.Protobuf

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

or whichever serializer you choose.

Clone this wiki locally