11

I have been using MassTransit and really like it. However, by default, it wraps all RabbitMQ payloads/messages with some JSON specific to MassTransit. This makes it difficult to exchange messages with non-.NET services. I know that JSON can be parsed by any language, but MassTransit is a .NET-only thing, and in my non-.NET services, I'd like to avoid having to add special logic to handle messages generated by MassTransit.

Is it possible to serialize JSON messages using MassTransit that don't go through the "MessageEnvelope" interface to establish better interoperability with non-MassTransit services? Or would doing this break most/all the MassTransit functionality?

Andy
  • 2,709
  • 5
  • 37
  • 64
  • 1
    Alexey responded, and his answer is right. It's JSON, and you'll find that the metadata in the envelope is important down the road. Message contracts are always going to be a first class concern, regardless of which language is being used. TL;DR: Leverage decades of messaging experience and realize the envelope makes total sense. – Chris Patterson Mar 30 '18 at 13:46
  • I appreciate the reply. Are you saying that if you were working with folks that have Java services, you would ask them to wrap all messages in the MessageEnvelope interface to ensure that MessageId, CorrelationId, etc. are set? I'm trying to figure out how to play nicely with non-.NET coworkers at my company. – Andy Mar 30 '18 at 21:10
  • Yes. I would. We even built a project to do that very thing for Java called MassTransit CrossTown :) – Chris Patterson Mar 30 '18 at 22:45
  • While I appreciate the creation of MassTransit CrossTown, it doesn't look like it offers Send and Request/Response patterns which is a showstopper for me. There's another project called JTransitLight that I was looking into, but it's also incomplete - they only support Bus.Publish. – Andy Apr 01 '18 at 19:11

1 Answers1

13

It is described in the documentation.

You won't be able to avoid having some special logic to consume MT messages since the format of messages is pre-defined.

This is a minimal message:

{
    "destinationAddress": "rabbitmq://localhost/input_queue",
    "headers": {},
    "message": {
        "value": "Some Value",
        "customerId": 27
    },
    "messageType": [
        "urn:message:MassTransit.Tests:ValueMessage"
    ]
}
Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83