Masstransit: Problem with MassTransit deserialization - 2

Created on 20 Feb 2020  路  3Comments  路  Source: MassTransit/MassTransit

I am having the same issue as here
I am trying to receive the message from rabbitmq were other application pushes data.
The data example is:

{"database":"test","table":"maxwell","type":"insert","ts":1582193439,"xid":6534,"commit":true,"data":{"id":1,"daemon":"Stanislaw Lem"}}

However I only see this error:

System.Runtime.Serialization.SerializationException: An exception occurred while deserializing the message envelope
---> System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.ToArrayTSource
at GreenPipes.Filters.RescueFilter2.GreenPipes.IFilter<TContext>.Send(TContext context, IPipe1 next)

The contract looks like this:

public class DatabaseChangeDto: IDatabaseChangeContract
{
    public string Database { get; set; }
    public string Table { get; set; }
    public string Type { get; set; }
    public DateTime Ts { get; set; }
    public long Xid { get; set; }
    public bool Commit { get; set; }
    public object Data { get; set; }
}

Most helpful comment

Is that really working @phatboyg ?
I have tried to consume raw json with using ClearMessageSerializers and UseRawJsonSerializer but consumer didn't catch the message, i got deserialization error!

This is real problem if the other applications publish their messages without masstransit.

Raw Json that is published from rabbitmq ui

{ "name": "hello world" }

Json contract

public class MyMessage 
{
    public string name {get; set; }
}

Consumer class

public class MyMessageConsumer: IConsumer<MyMessage>
{
       public Task Consume(ConsumeContext<MyMessage> context)
        {

        }
}

Bus configurations

      cfg.ReceiveEndpoint("rawjsonqueue", ep =>
                {
                    ep.ClearMessageSerializers();
                    ep.UseRawJsonSerializer();

                    ep.ConfigureConsumer<MyMessageConsumer>(serviceProvider);
                });

I expected to catch the message from consumer.

All 3 comments

You could configure the receive endpoint as raw JSON, and use whatever message type to deserialize.

endpoint.UseRawJsonSerializer();

That will deserialize if the content type is application/json. If you can't set the content type, you'll need to call ClearSerializers (close, might be ClearMessageSerializers) to remove the built-in ones and make raw the default.

Is that really working @phatboyg ?
I have tried to consume raw json with using ClearMessageSerializers and UseRawJsonSerializer but consumer didn't catch the message, i got deserialization error!

This is real problem if the other applications publish their messages without masstransit.

Raw Json that is published from rabbitmq ui

{ "name": "hello world" }

Json contract

public class MyMessage 
{
    public string name {get; set; }
}

Consumer class

public class MyMessageConsumer: IConsumer<MyMessage>
{
       public Task Consume(ConsumeContext<MyMessage> context)
        {

        }
}

Bus configurations

      cfg.ReceiveEndpoint("rawjsonqueue", ep =>
                {
                    ep.ClearMessageSerializers();
                    ep.UseRawJsonSerializer();

                    ep.ConfigureConsumer<MyMessageConsumer>(serviceProvider);
                });

I expected to catch the message from consumer.

Was this page helpful?
0 / 5 - 0 ratings