ProtoBuf-Net Serializer Usage

Component: ProtoBuf-Net Serializer
NuGet Package NServiceBus.ProtoBuf (2-pre)
This is a community run project
Target NServiceBus Version: 7.x
This page targets a pre-release version and is subject to change prior to the final release.

Configuring to use ProtoBuf

var endpointConfiguration = new EndpointConfiguration("Samples.Serialization.ProtoBuf");
endpointConfiguration.UseSerialization<ProtoBufSerializer>();

The message definition

[ProtoContract]
public class CreateOrder :
    IMessage
{
    [ProtoMember(1)]
    public int OrderId;

    [ProtoMember(2)]
    public DateTime Date;

    [ProtoMember(3)]
    public int CustomerId;

    [ProtoMember(4)]
    public List<OrderItem> OrderItems;
}

The message send

var message = new CreateOrder
{
    OrderId = 9,
    Date = DateTime.Now,
    CustomerId = 12,
    OrderItems = new List<OrderItem>
    {
        new OrderItem
        {
            ItemId = 6,
            Quantity = 2
        },
        new OrderItem
        {
            ItemId = 5,
            Quantity = 4
        },
    }
};
await endpointInstance.SendLocal(message)
    .ConfigureAwait(false);

Related Articles


Last modified