ProtoBuf-Net Serializer

Project Hosting
NuGet Package NServiceBus.ProtoBuf (2-pre) | License
This is a community run project. License and support are independent of Particular Software.
Target NServiceBus Version: 7.x
This page targets a pre-release version and is subject to change prior to the final release.

Serializes messages using protobuf-net.

There are two serializers that target Protocol Buffers. The ProtoBuf-Google serializer targets the Google.Protobuf NuGet package, while the ProtoBuf-Net serializer targets the protobuf-net NuGet package.

Usage

endpointConfiguration.UseSerialization<ProtoBufSerializer>();
This serializer does not support Messages defined as Interfaces.If an explicit interface is send an exception will be thrown with the following message:

Interface based message are not supported.
Create a class that implements the desired interface

Instead use a public class with the same contract as the interface. The class can optionally implement any required interfaces.

Custom Settings

Customizes the instance of SerializerOptions used for serialization.

var runtimeTypeModel = TypeModel.Create();
runtimeTypeModel.IncludeDateTimeKind = true;
var serialization = endpointConfiguration.UseSerialization<ProtoBufSerializer>();
serialization.RuntimeTypeModel(runtimeTypeModel);

Custom Content Key

When using additional deserializers or transitioning between different versions of the same serializer it can be helpful to take explicit control over the content type a serializer passes to NServiceBus (to be used for the ContentType header).

var serialization = endpointConfiguration.UseSerialization<ProtoBufSerializer>();
serialization.ContentTypeKey("custom-key");

Samples

Related Articles


Last modified