Read MsgPack message from Rabbit MQ

I’m trying to read message in MsgPack format from RabbitMQ with service stack.
I have try to register a custom format in AppHost config method:

StreamSerializerDelegate serializer = (request, obj, str) => {
            var obj1 = obj; // I have set a breakpoint here
};
StreamDeserializerDelegate deserializer = (type, stream) => {
        return new object();  // and a breakpoint in here
};
this.ContentTypes.Register("application/msgpack", serializer, deserializer);

And here is code which used to publish a message to RabbitMQ in MsgPack format:

public void PublishMessage<T>(IModel channel, string exchange, string routingKey, T obj, IDTOSerializer serializer)
    {
        var props = channel.CreateBasicProperties();
        props.ContentType = "application/msgpack";
        props.Persistent = true;
        channel.BasicPublish(exchange, routingKey, props, serializer.Serialize<T>(obj));
    }

The message was published to the queue successfully, but Servicestack don’t recognize my contenttype and none of my breakpoints hit.

Here is the message in RabbitMQ:

Can anyone show me what i’m missing?
Thank you so much.

Did you register MsgPack plugin in Configure method? And can you provide small stand-alone sample we’ll look into it to see what happens?

Hi xplicit,
I don’t use any plugin, i just register for a custom media type and serialize/ deserialize the data myself.
I follow this article: Serialization and Deserialization
I have read this article about MsgPack plugin: MsgPack Format
But it just make no sence to me. If you have done this before, please give me some advice.
Thank you.

ServiceStack MQ only supports sending/receiving complex type messages in JSON but I’ve just added support for allowing different registered formats in this commit which is now available from v4.5.13 that’s now available on MyGet.

To use MsgPack in ServiceStack as the documentation states you need to install the ServiceStack.MsgPack NuGet package:

PM> Install-Package ServiceStack.MsgPack 

Then register the format in your AppHost.Configure() (i.e. where all AppHost Configuration is) with:

Plugins.Add(new MsgPackFormat());

Note we have no control over the serialization/deserialization implementation of external formats which wont have all the features and coverage that our Serializers do.

Hi mythz,
I do exactly those step except i can’t install v4.5.13 because 4.5.12 is last stable version in nuget package manager.
Since i use .Net Core, i have to install the core package

PM> Install-Package ServiceStack.MsgPack.Core

I also add this line to the first line of AppHost’s Configuration method:

Plugins.Add(new MsgPackFormat());

But the problem is remain.
After reading ServiceStack.Msgpack code, i found that it just do the same thing as i did: register a custom media type:

public class MsgPackFormat : IPlugin, IMsgPackPlugin
{
    public void Register(IAppHost appHost)
    {
        appHost.ContentTypes.Register(MimeTypes.MsgPack,
            Serialize,
            Deserialize);
    }
}

But i can’t found what MimeTypes.MsgPack is. The only thing i can found is android client:
ServiceStack/ServiceStack.Java

So, i give it a try by change my content type to application/x-msgpack like this:

public void PublishMessage<T>(IModel channel, string exchange, string routingKey, T obj, IDTOSerializer serializer)
    {
        var props = channel.CreateBasicProperties();
        props.ContentType = "application/x-msgpack"
        channel.BasicPublish(exchange, routingKey, props, serializer.Serialize<T>(obj));
    }

But again, the problem is still remain.

Note that my project work well with JSON.

Please read and follow answers carefully, v4.5.13 is available on MyGet. If you’re using v4.5.12 you will not have this change and you can only use JSON.

If you’re using .NET Core then you will need to install v1.0.44 of ServiceStack.MsgPack.Core instead that is also on MyGet. The docs also show how to add the MyGet feed when not using VS.NET.

This is what you need to add to your AppHost to register the MsgPack format:

Plugins.Add(new MsgPackFormat()); 

Don’t do anything else, this is the only supported way to register the MsgPack format in ServiceStack.

MimeTypes.MsgPack is defined in ServiceStack.Text/ServiceStack.Text.Core NuGet packages in the ServiceStack namespace.

Don’t bother trying to use any other Content-Type unless you’re using v4.5.13 / v1.0.44 .NET Core NuGet packages, it expects and only supports JSON.