Search code examples
azuremasstransitazure-servicebus-topics

How to customize a masstransit payload when pushing on Azure-topics


I'm using Mass-transit for a few tasks, and now I have a new request which is send a message to an Azure topics. Everything is fine, except that the payload has too much information and the consummers don't necesseraly use Mass-transit on their end.

What I want to do right now is to customize my payload in order to have a full custom payload.

I've seen that you can add some information in the header, but no information about a clean start on your message. Is it even possible ?

Thanks


Solution

  • You could create your own message serializer, which would give you full control over the message body. You could also use the raw JSON serializer, which only serializes the message itself into the body.

    Serializers aren't really documented on the original documentation site, but the new site has a lot more detail (site isn't finished yet, but this page is likely helpful).

    Update

    If you just want raw JSON, follow the documentation I linked:

    cfg.UseRawJsonSerializer(RawSerializerOptions.AddTransportHeaders | RawSerializerOptions.CopyHeaders);
    

    Creating your own serializer is not documented (nor are there plans to document it at this time).