MassTransit Send Only Message Body

Viewed 291

Looking into using MassTransit to replace some old brittle ActiveMQ libraries my company is using. Currently the messages that we send to AMQ are basically JUST the object

{
    "clientId": 1,
    "accountid": 333,
    "filePath": "C:\Test.csv",
    "updateDate": "2021-11-08T23:37:39.2915758Z"
}

When I send my message through MassTransit though, it adds a ton of other information to the message...

{
  "messageId": "00010000-4100-0250-5531-08d9a310c15e",
  "conversationId": "00010000-4100-0250-577a-08d9a310c15e",
  "sourceAddress": "activemq://localhost:61616/WINDOWZZZ123_MyCompanyStreamService_bus_yyyoyynbyybfynjjbdc4grfire?temporary=true",
  "destinationAddress": "activemq://localhost:61616/MessageQueue_Testing",
  "messageType": [
    "urn:message:MyCompany.Services.QueueContracts:MessageQueueItem",
    "urn:message:MyCompany.Services.QueueContracts:IQueueItem"
  ],
  "message": {
    "clientId": 1,
    "accountId": 333,
    "filePath": "C:\Test.csv",
    "updateDate": "2021-11-08T23:37:39.2915758Z"
  },
  "sentTime": "2021-11-08T23:37:40.8624945Z",
  "headers": {
    "MT-Activity-Id": "00-b8b6cf020495eb44b57c8eff14244671-937ecff1f3901d41-01"
  },
  "host": {
    "machineName": "WINDOWZZZ123",
    "processName": "MyCompany.StreamService",
    "processId": 25692,
    "assembly": "MyCompany.StreamService",
    "assemblyVersion": "1.0.0.0",
    "frameworkVersion": "5.0.11",
    "massTransitVersion": "7.2.4.0",
    "operatingSystemVersion": "Microsoft Windows NT 10.0.19043.0"
  }
}

While I see the value of having all of that metadata, it will break all of our legacy services and is too much work for now.

I am setting up MassTransit like so... Startup.cs ConfigureSerives()

services.AddMassTransit(x =>
{
    x.UsingActiveMq((context, cfg) =>
    {
        cfg.Host("localhost", h =>
        {
            h.Username("admin");
            h.Password("admin");
        });
    });
});
services.AddMassTransitHostedService();

I am Sending the message like this....

var endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("queue:myQueue"));
var item = new MessageQueueItem();
await endpoint.Send<MessageQueueItem>(item);

From looking at the docs, it seems like maybe MassTransit isn't really built for this use case and is more suited for building systems that all work together using MT?

Thanks for any help! -Greg

1 Answers

You can switch to the raw JSON serializer if needed, simply by changing your bus configuration:

services.AddMassTransit(x =>
{
    x.UsingActiveMq((context, cfg) =>
    {
        cfg.Host("localhost", h =>
        {
            h.Username("admin");
            h.Password("admin");
        });

        cfg.UseRawJsonSerializer();
    });
});
services.AddMassTransitHostedService();

That will send the message only, without the message envelope.

Related