pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
747 stars 144 forks source link

Beta8: Serialization type #255

Closed msnelling closed 7 years ago

msnelling commented 7 years ago

Hi, I'm looking at porting our app to use RawRabbit 2.0. Beta 8 defines the ISerializer interface as

  public interface ISerializer
  {
    string ContentType { get; }
    string Serialize(object obj);
    object Deserialize(Type type, string str);
    TType Deserialize<TType>(string str);
  }

How will this work if say my messages are to be serialised as binary protocol buffer messages when the Serialize() function returns a string instead of byte[]?

pardahlman commented 7 years ago

Hello @msnelling - thanks for reporting this.

I believe that you are right, the ISerializer assumes that you serialize to string based output (like json, xml ...). At a first glance in the code, it shouldn't be that big of an effort to update the signature, but I have to look closer at it before committing to this change.

In the mean while, it shouldn't be that difficult working around this, as the client is can easily be modified. The bytes of a published message is extracted from the serialized message (string), and it is possible to update/replace that middleware by using the fluent builder in the Plugin property of RawRabbitOptions.

msnelling commented 7 years ago

Thanks. I'm having trouble with the Plugin syntax, are there any examples?

pardahlman commented 7 years ago

You can have a look at the Enrichers in the 2.0 branch. There is unfortunately no better documentation at this point.

pardahlman commented 7 years ago

Hello again. I've updated the ISerializer interface so that it works with byte arrays. To verify that it works, I've also created an enricher that changes serializer to protobuf 👉 https://github.com/pardahlman/RawRabbit/blob/2.0/test/RawRabbit.IntegrationTests/Enrichers/ProtobufTests.cs

This will be part of beta9.

msnelling commented 7 years ago

Thanks!

pardahlman commented 7 years ago

Released