Problem with MassTransit deserialization

See original GitHub issue

Okay so I have a problem with using MassTransit and it’s deserialization.

We’re publishing messages into a specific queue with RabbitMQ, which should then be further processed by our background services using MassTransit.

The string coming in through the queue looks as following

{

  "routingKey": "article.put",

  "responseQueue": {

    "exchange": "testexchange_gateway",

    "responseRoutingKey": "gatewayResponseQueue",

    "vhost": "testvhost"

  },

  "deviceProperties": {

    "deviceType": "DESKTOP",

    "deviceSize": {

      "width": 10,

      "height": 10

    },

    "javascriptEnabled": false

  },

  "action": "PUT",

  "transactionId": "62b6174d-04b7-4937-b617-4d04b70937b0",

  "contentType": "application/json",

  "body": "Testmessage published while running"

}

With the Contract looking like

public interface IMessage
   {
       string routingKey { get; set; }
       ResponseQueue responseQueue { get; set; }
       DeviceProperties deviceProperties { get; set; }
       string action { get; set; }
       string transactionId { get; set; }
       string contentType { get; set; }
       string body { get; set; }
   }
public interface ResponseQueue
    {
        string exchange { get; set; }
        string responseRoutingKey { get; set; }
        string vhost { get; set; }
    }
 public interface DeviceProperties
    {
        string deviceType { get; set; }
        DeviceSize deviceSize { get; set; }
        bool javascriptEnabled { get; set; }

    }

    public interface DeviceSize
    {
        int width { get; set; }
        int height { get; set; }
    }

My problem now is, whenever I want to consume that message using MassTransit, I will get an error in my _error queue:

MT-Fault-ExceptionType: | System.ArgumentNullException
-- | --
Value cannot be null. Parameter name: source
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at MassTransit.Serialization.JsonConsumeContext..ctor(JsonSerializer deserializer, IObjectTypeDeserializer objectTypeDeserializer, ReceiveContext receiveContext, MessageEnvelope envelope) at MassTransit.Serialization.JsonMessageDeserializer.MassTransit.IMessageDeserializer.Deserialize(ReceiveContext receiveContext)

which I don’t quite understand, as all values needed should be right there.

My consumer:

class ArticleGetConsumer : IConsumer<IMessage>
    {
        public Task Consume(ConsumeContext<IMessage> context)
        {
            var routingKey = context.Message.routingKey;
            return Task.FromResult(0);
        }
    }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
phatboygcommented, Sep 18, 2018

Should look like this:

{
  "destinationAddress": "rabbitmq://localhost/input_queue",
  "headers": {},
  "messageType": [
    "urn:message:YourProject.Messages:IMessage"
    ],
  "message": {
    "routingKey": "article.put",
    "responseQueue": {
      "exchange": "testexchange_gateway",
      "responseRoutingKey": "gatewayResponseQueue",
      "vhost": "testvhost"
    },
    "deviceProperties": {
      "deviceType": "DESKTOP",
      "deviceSize": {
        "width": 10,
        "height": 10
      },
      "javascriptEnabled": false
    },
    "action": "PUT",
    "transactionId": "62b6174d-04b7-4937-b617-4d04b70937b0",
    "contentType": "application/json",
    "body": "Testmessage published while running"
  }
}
1reaction
phatboygcommented, Jul 13, 2021

Sounds like you need to use the RawJsonMessageDeserializer.

Covered in this video.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with MassTransit deserialization - 2 · Issue #1707
I am having the same issue as here I am trying to receive the message from rabbitmq were other application pushes data.
Read more >
How to avoid incompatible during deserializing ...
When using the request/response pattern, during the deserialization of the response, an incompatibility error occurs. Apparently, the publisher ...
Read more >
Handling a message produced by MassTransit
MessageDeserializationException : An error occurred while attempting to extract logical messages from incoming physical message ...
Read more >
Message Serialization
To interoperate with other languages and platforms, message structure is important. MassTransit encapsulates messages in an envelope before they are serialized.
Read more >
JSON Serilization configuration issue.
I am trying to configure the serializerd on Mass Transit to make sure it ... JsonSerializationException: Cannot deserialize the current JSON ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found